Jump to content

Ajax file url


mvdesign
 Share

Recommended Posts

Hello,

I'm trying to get a file url, using ajax with the page ID :

$file = wire('pages')->get($id)->file->url;

But it outputs the file url without the filename :

/site/assets/files/xxxx/ instead of /site/assets/files/1017/filename.ext

No problem from a template file...

Any solution ? Thanks !

Link to comment
Share on other sites

@mvdesign: sorry, corrected my earlier post -- meant to say bootstrap use, not API use. The principle was correct, though; if I'm guessing right, you're bootstrapping ProcessWire, and thus output formatting is always disabled and file fields will always return arrays, regardless of output settings (including the "output single item if limit is one" setting).

  • Like 1
Link to comment
Share on other sites

I already know the problem/answer just by reading post titles like this one in this forum. This problem has come up and answered 1001 times at least. 

I even got in a heated discussion with a co-worker about this, where he just don't get outputformatting, even after explaining him multiple times again and again. He even insisted on that in his particular case it doesn't work even though it should have... 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...