robert Posted June 20, 2018 Share Posted June 20, 2018 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 More sharing options...
robert Posted June 20, 2018 Author Share Posted June 20, 2018 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 More sharing options...
adrian Posted June 20, 2018 Share Posted June 20, 2018 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. 3 Link to comment Share on other sites More sharing options...
robert Posted June 21, 2018 Author Share Posted June 21, 2018 Hi Adrian, you are absolutely right! As soon as I switch output formatting off, the results are identically. Thanks for the fast clarification ? 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now