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

Support Images without Extensions #14

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

synatree
Copy link

@synatree synatree commented Sep 21, 2022

One problem with the extension is that a URL that looks like this: https://domain.com/download?id=123 doesn't have a file extension. The thumbnailer still works fine if this is the case (as long as the thumb is used in an <img> tag), but in many default setups the image will bear the content-type "application/octet-stream". If this image is linked to, it will download rather than showing in the browser window by default. This causes it to fail, for example, when used with GLightBox.

This PR adds a dependency, which is needed because Yii2's FileHelper::getExtensionsByMimeType returns silly answers for common MIMEs. For example, Yii2's answer to "image/jpeg" is ".jfif". By default, httpd will serve .jfif as application/octet-stream.

The MIME type is determined either using FileHelper::getMimeType() which fails for URLs, or using get_headers() to fetch the Content-Type of the remote image.

I also added Inflector::slug to correct unusual characters in the filename which caused problems with file retrieval, and hashed the querystring. This just makes the generated names a little more sane and removes characters like "&", "?", and "=".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant