No Code Attached Yet Information Required bug
avatar coderiekelt
coderiekelt
10 Oct 2023

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']));
avatar coderiekelt coderiekelt - open - 10 Oct 2023
avatar joomla-cms-bot joomla-cms-bot - change - 10 Oct 2023
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 10 Oct 2023
avatar Quy
Quy - comment - 10 Oct 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.

avatar coderiekelt
coderiekelt - comment - 10 Oct 2023

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.

avatar Quy
Quy - comment - 10 Oct 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.

avatar brianteeman
brianteeman - comment - 10 Oct 2023
  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)
avatar richard67 richard67 - change - 10 Oct 2023
Labels Added: Information Required
avatar richard67 richard67 - labeled - 10 Oct 2023
avatar dgrammatiko
dgrammatiko - comment - 10 Oct 2023

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)...

avatar coderiekelt
coderiekelt - comment - 11 Oct 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

avatar peteruoi
peteruoi - comment - 19 Oct 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 !

avatar Hackwar Hackwar - change - 27 Mar 2024
Labels Added: bug
avatar Hackwar Hackwar - labeled - 27 Mar 2024
avatar richard67 richard67 - change - 24 Apr 2024
Status New Closed
Closed_Date 0000-00-00 00:00:00 2024-04-24 13:13:35
Closed_By richard67
avatar richard67 richard67 - close - 24 Apr 2024
avatar richard67
richard67 - comment - 24 Apr 2024

Closing as having a pull request. See #43345 .

Add a Comment

Login with GitHub to post a comment