Jump to content

Retrieving wrong (non-croped) file with filesManager


Noel Boss
 Share

Recommended Posts

Short description of the issue

Since PW 3.0.88: When I try to retrive a croped file using the api filesManager() and it's basename, I get the original version instead of the croped variation.

Expected behaviour

Looking up a variation using the path and filesManager should return the variation file.

 $page->filesManager->getFile("/path/to/filebasename.400x400.jpg"); // $file->basename > filebasename.400x400.jpg

Actual behavior

The variation is returned.

 $page->filesManager->getFile("/path/to/filebasename.400x400.jpg"); // $file->basename > filebasename.jpg

 

» Is this a bug or do I miss something here?

 

Code:

dump($page->filesManager->path.$input->get->filename('f'));
$file = $page->filesManager->getFile($page->filesManager->path.$input->get->filename('f'));
dump($file);
dump($page->filesManager->path.$file->basename);

Output:

"/home/ubuntu/workspace/www/site/assets/files/-1579/colin-rex-434063.400x400.jpg" (79)
ProcessWire\Pageimage #796f
pageimages protected => ProcessWire\Pageimages #d195 original protected => ProcessWire\Pageimage #796f { RECURSION } variations private => null imageInfo private => array (2)
width => 0 height => 0
error protected => "" pagefiles protected => ProcessWire\Pageimages #d195 data protected => array (6)
basename => "colin-rex-434063.jpg" (20) description => "" tags => "" formatted => true modified => 1516025386 created => 1516025386
useFuel protected => true _instanceNum private => 870 localHooks protected => array () trackChanges private => 2 changes private => array (1)
formatted => array (1)
0 => null
_notices protected => array (3)
errors => null warnings => null messages => null
_wire protected => ProcessWire\ProcessWire #28d0

in .../www/site/templates/app/utils/download.php:29

"/home/ubuntu/workspace/www/site/assets/files/-1579/colin-rex-434063.jpg" (71)

Link to comment
Share on other sites

5 hours ago, noelboss said:

Is this a bug or do I miss something here?

It looks like a deliberate decision to get the original Pageimage if a variation name is given. See here. So I don't think it's a bug.

Perhaps the expectation is that if you want a variation you will always get that from the original Pageimage with one of the resizing methods. For example:

$pageimage = $page->filesManager->getFile("/path/to/filebasename.jpg");
$variation = $pageimage->size(400,400);

This seems like the way to go because that way the variation is created in the event that it was somehow removed previously. Will this work for you?

  • Like 1
Link to comment
Share on other sites

Not really an option because I'm leaving the context of the page. I don't want to link the file directly for several reasons…

If I specify a variation, I should also get the variation imho, because I can always get the original easily using these methods: 

// or https://processwire.com/api/ref/pageimage/
$image->original;
// or
$image->getOriginla();

But it's kind of a hack to extract the crop from the file-name and get the variation instead.

Link to comment
Share on other sites

  • 4 weeks later...

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

×
×
  • Create New...