Jump to content

Differences between browser and command line API access


robert
 Share

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;
var_dump($img->filename);
var_dump($img->basename);
var_dump($img->url);
var_dump($img->path);

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!

Link to comment
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). 

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...