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

Certain SVG file is not allowed in image only upload directory #2808

Closed
shbchk opened this issue Feb 1, 2023 · 14 comments · Fixed by #2811
Closed

Certain SVG file is not allowed in image only upload directory #2808

shbchk opened this issue Feb 1, 2023 · 14 comments · Fixed by #2811

Comments

@shbchk
Copy link

shbchk commented Feb 1, 2023

EE 7.2.8

This SVG image can not be uploaded as an image in EE:

dfddbac7-8de9-4c91-93da-23abb05eb47c

@intoeetive
Copy link
Contributor

I wasn't able to replicate this.

If other SVG files work fine, I suggest that you open this file in code editor and check if it looks like valid XML

@shbchk
Copy link
Author

shbchk commented Feb 1, 2023

It sure does look like valid XML:

image

And I just replicated it, using a clean copy of EE 7.2.8.

Here are the steps:

  1. Create an upload directory:
    78a5588b-507b-4d66-9185-3e9929f6a598

  2. Download this SVG file from Wikipedia: https://upload.wikimedia.org/wikipedia/commons/e/ef/Tribeca_Festival_logo.svg

  3. Try to upload it.
    abc16179-4936-4d90-a27e-0aee08af8592

@shbchk
Copy link
Author

shbchk commented Feb 1, 2023

PHP Version 7.4.21, btw

@shbchk
Copy link
Author

shbchk commented Feb 1, 2023

Okay, you are right, it's not exactly valid - there is a declaration missing:
<?xml version="1.0" encoding="utf-8"?>

After I added it, EE accepted the file.

I guess, it is the correct behavior. Correct, but do you think it's good? It could be confusing for an editor, to be able to download an image from one website, where it is rendering totally fine, but not to be able to upload it to another.

@intoeetive
Copy link
Contributor

The file still should be accepted, despite missing <?xml part

There must be something specific in how your server handles MIME types.

Can you do some checks for me?
Try editing system\ee\ExpressionEngine\Library\Mime\MimeType.php file and on line 219 right after $mime = $this->ofFile($path); add this code

dd($mime);

Upload the file and inspect browser console for network requests (because the upload is AJAX).
I'm interested to know what MIME type it returns for you

@intoeetive intoeetive reopened this Feb 1, 2023
@shbchk
Copy link
Author

shbchk commented Feb 1, 2023

I have three EE installs: localhost, Digital Ocean droplet, and a simple virtual hosting for a small website. And everywhere this file wasn't accepted, so this is not because of my setup, I guess :)

With dd($mime); it throws an error in a console.

I made a video!
video-convert-1675248898946.webm

@intoeetive
Copy link
Contributor

The error is expected in this case; I'd like to see what is returns in Response tab for this request

@shbchk
Copy link
Author

shbchk commented Feb 1, 2023

Sorry, I'm not a true dev. Yet :)

Here it is:

<pre>string(9) "image/svg"
</pre>

BTW, sometimes, when I click on a file to upload it gets uploaded twice, like in the screenshot below. Not sure though why it is happening and how to replicate it.

image

@intoeetive
Copy link
Contributor

Interesting. This should just work.

Do you by chance have mimes.php file in system/user/config folder? If yes, what is the contents of it?

Also, you don't have any manipulations (resize / crop) assigned to this upload directory, right?

@shbchk
Copy link
Author

shbchk commented Feb 1, 2023

No, no mimes.php on both local copies of EE - test install and the dev environment of my website.

I got manipulations on dev environment, but no manipulations on the test installation — it is fresh and clean, just installed for testing purposes.

@intoeetive
Copy link
Contributor

Ok. If you change line 224 (if ($mime == 'image/svg+xml') {) to if (strpos($mime, 'image/svg') === 0) { - does that make things work?

@shbchk
Copy link
Author

shbchk commented Feb 1, 2023

Yes, now EE is accepting this file!

@intoeetive
Copy link
Contributor

Great! Thanks for helping me debug this

@shbchk
Copy link
Author

shbchk commented Feb 1, 2023

Always a pleasure, Yuri! Glad to help you and EE :)

intoeetive added a commit that referenced this issue Feb 1, 2023
intoeetive added a commit that referenced this issue Feb 1, 2023
bryannielsen added a commit that referenced this issue Feb 2, 2023
Resolved #2808 where some servers did not accept SVG files to be uploaded into image-only directory
bryannielsen added a commit that referenced this issue Feb 2, 2023
Resolved #2808 where some servers did not accept SVG files to be uploaded into image-only directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants