Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File::getIsImage() always returns false, even if the file is an image. #594

Open
2 tasks done
GuySartorelli opened this issue Feb 20, 2024 · 0 comments
Open
2 tasks done

Comments

@GuySartorelli
Copy link
Member

GuySartorelli commented Feb 20, 2024

Module version(s) affected

4.*, 5.*

Description

If you create a new file, and the file is an image, and you call $file->getIsImage(), it returns false if you created it using the File class.

How to reproduce

Execute the below code, where $someFileLocation is the path to a file on your filesystem.

Regardless of what type of file that is, whether it's an image or not, false will be dumped out.

use SilverStripe\Assets\File;

$file = File::create();
$file->setFromLocalFile($someFileLocation);
$file->write();

// Publish the file
$file->publishFile();

var_dump($file->getIsImage());

Possible Solution

Check $this->appCategory(), e.g:

public function getIsImage()
{
    return in_array($this->appCategory(), ['image', 'image/supported']);
}

That won't capture images that developers put in custom app categories - but I think that's an edge case we can live with.

Additional Context

No response

Validations

  • Check that there isn't already an issue that reports the same bug
  • Double check that your reproduction steps work in a fresh installation of silverstripe/installer (with any code examples you've provided)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant