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

Unable to upload PDF files in Media library #42105

Closed
coderiekelt opened this issue Oct 10, 2023 · 8 comments
Closed

Unable to upload PDF files in Media library #42105

coderiekelt opened this issue Oct 10, 2023 · 8 comments

Comments

@coderiekelt
Copy link
Contributor

PHP version: 8.2.6
Joomla version: 4.2.8

After upgrading to Joomla 4.2 (a while ago) I've gotten complaints from users that they are unable to upload PDF files in the Media library.

Upon some investigation it turns out that Joomla assumes that any file a user uploads is an image, and fails to get the Mime Type for the uploaded file, as it's not an image.

Upon investigation it turns out that this line of code is causing the issue:

$mime = static::getMimeType($file['tmp_name'], true);

The whitelist a bit above that line will also cause Joomla to think that document files are images:

$allowedExtensions = array_map('trim', explode(',', $params->get('restrict_uploads_extensions', 'bmp,gif,jpg,jpeg,png,webp,avif,ico,mp3,m4a,mp4a,ogg,mp4,mp4v,mpeg,mov,odg,odp,ods,odt,pdf,png,ppt,txt,xcf,xls,csv')));

I have to admit that I'm not familiar enough to know if this is a mistake on my part, but changing line 277 to the following resolved my issue:

$mime = static::getMimeType($file['tmp_name'], static::isImage($file['tmp_name']));
@Quy
Copy link
Contributor

Quy commented Oct 10, 2023

Under Media, select one of these PDFs and click the i icon. What is its mime type? Make sure it is listed in Legal MIME Types under the Media settings.

This is better posted @ https://forum.joomla.org/ as it appears to be a support question specific to your setup.

@coderiekelt
Copy link
Contributor Author

The file is listed as Mime Type: "application/pdf" and extension: "pdf"

pdf is configured as a legal document extension, and application/pdf is configured as a legal mime type.

@Quy
Copy link
Contributor

Quy commented Oct 10, 2023

I am not able to reproduce it with v4.3.4. Maybe you can test with a separate clean installation using the latest version.

@brianteeman
Copy link
Contributor

  1. When they are unable to upload the pdf an error message is displayed. What is it?
  2. Long shot but is fileinfo enabled you can find out at administrator/index.php?option=com_admin&view=sysinfo)

@dgrammatiko
Copy link
Contributor

Can you please share your media manager options? I suspect that you've followed some wrong tutorial or you have some plugin that is really bad (assigns pdf to images)...

@coderiekelt
Copy link
Contributor Author

coderiekelt commented Oct 11, 2023

@brianteeman The error states that the file uploaded is not a valid image, Fileinfo Available displays Yes.

@dgrammatiko
Maximum Size (MB): 15
Path to files: images
Path to images: images
Restrict uploads: Yes
Allowed extensions: bmp,gif,jpg,jpeg,png,webp,ico,mp3,mp4,odg,odp,ods,odt,pdf,png,ppt,txt,xcf,xls,csv,doc,docx,xlsx,pptx,dotx,zip
Check MIME-types: Yes
Allowed image extensions: bmp,gif,jpg,png
Legal Audio Extensions: mp3,m4a,mp4a,ogg
Legal Video Extensions: mp4,mp4v,mpeg,mov,webm
Legal Document Extensions: doc,odg,odp,ods,odt,pdf,ppt,txt,xcf,xls,csv,docx,xlsx,pptx,zip,dotx
Illegal extensions: blank
Allowed MIME-types:

image/jpeg,image/gif,image/png,image/bmp,application/x-shockwave-flash,
application/msword,application/excel,application/pdf,application/powerpoint,
text/plain,application/x-zip,application/vnd.openxmlformats-officedocument.wordprocessingml.document,
application/vnd.openxmlformats-officedocument.wordprocessingml.template,application/vnd.ms-word.document.macroEnabled.12,
application/vnd.ms-word.template.macroEnabled.12,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,
application/vnd.openxmlformats-officedocument.spreadsheetml.template,application/vnd.openxmlformats-officedocument.presentationml.presentation,
application/vnd.openxmlformats-officedocument.presentationml.slideshow,video/mp4,
application/zip,application/x-7z-compressed,application/zip-compressed,application/x-zip-compressed,
application/octet-stream,multipart/x-zip,application/x-compress,application/x-compressed

Forbidden MIME-types: text/html

@peteruoi
Copy link

peteruoi commented Oct 19, 2023

I am not sure if this is relevant here. I cannot upload pdfs. I have a very similar problem with [https://forum.joomla.org/viewtopic.php?t=1002182]
However i found an error in the console.
/administrator/index.php?option=com_media&format=json&mediatypes=0,1,2,3&task=api.files&path=local-images:/content/pdfs/2023](administrator/index.php?option=com_media&format=json&mediatypes=0,1,2,3&task=api.files&path=local-images%3A%2Fcontent%2Fpdfs%2F2023
[HTTP/1.1 403 Forbidden 1332ms]
the http headers plugin is disabled.
If you think is relevant here i can add more info.
Tje strange thing is that when i worked this site in a development server file uploading worked !

@richard67
Copy link
Member

Closing as having a pull request. See #43345 .

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

8 participants