Jump to content

Differences between browser and command line API access

Recommended Posts

I’m trying to get the filename of a file in an imagefield via command line, but there seems to be a difference between the API access via browser and via command line. When I try the following (reduced case):

$img = $pages->get('/')->name_of_imagefield;

I get these results:

Browser (as expected):

  • filename: full path to file including name (e.g. /var/www/public/site/assets/files/1/filename.jpg)
  • basename: only name without path (e.g. filename.jpg)
  • url: webroot-based path to file including name  (e.g. /site/assets/files/1/filename.jpg)
  • path: NULL

Command Line:

  • filename: NULL
  • basename: NULL
  • url: webroot-based path to file WITHOUT filename (e.g. /site/assets/files/1/)
  • path: full path to file WITHOUT filename (e.g. /var/www/public/site/assets/files/1/)

What am I missing? Or is this normal behaviour and I just never noticed before? The website is running Processwire 3.0.94 with PHP 7.0.

Thanks a lot for any help!

Share this post

Link to post
Share on other sites

What a coincidence! Just one second after my post, I found this topic and horsts answer helped me as well. Thanks a lot, horst! 🙂 I still don’t understand why there were differences between command line and browser, but when I add $img->first()->filename, I get identical results (although the maximum file amount in the imagefield was set to 1, btw). 

Share this post

Link to post
Share on other sites

I think you're coming across the fact that on the command line outputformatting is always off so image fields always return an array regardless of the config settings.

  • Like 3

Share this post

Link to post
Share on other sites

Hi Adrian,

you are absolutely right! As soon as I switch output formatting off, the results are identically. Thanks for the fast clarification 🙂

  • Like 1

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...