class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
My logfile says: system information - class version : 30/08/2022 - operating system : Linux - PHP version : 8.1.2 - GD version : 2.2.4 - supported image types : png webp jpg gif bmp - open_basedir : /var/customers/webs/test3:/var/customers/tmp/test3:/usr/share/php:/usr/share/php5:/tmp - upload_max_filesize : 64M (67108864 bytes) - language : de_DE source is an uploaded file - upload OK - file name OK determining MIME type - checking MIME type with Fileinfo PECL extension MAGIC path will not be used MIME type detected as application/encrypted; charset=binary by Fileinfo PECL extension - MIME validated as application/encrypted source variables - you can use all these before calling process() file_src_name : GAR_Datenbank_aktuell_2022_10_10_RAY.xls file_src_name_body : GAR_Datenbank_aktuell_2022_10_10_RAY file_src_name_ext : xls file_src_pathname : /var/customers/tmp/test3/phprKRUn8 file_src_mime : application/encrypted file_src_size : 415232 (max= 67108864) file_src_error : 0 process file to /var/customers/webs/test3/dskom/media/uploaders_649615/71/in/ - file size OK - MIME type and/or extension is not allowed ! - error: Falscher Dateityp.
In addition: I created myself files .xlsx and .xls and upload works fine. Is it possible that the customer files are corrupt in some way though the file obviously opens and reads fine?Reply
On your OS (LInux), the class uses FileInfo PECL extension to detect MIME type, and it detects application/encrypted, which is very generic, and dangerous to allow.
You may try to deactivate FileInfo in order to rely instead on Unix file command: deactivate the code using fileinfo in the class. Search for this line in the class:
system information - class version : 30/08/2022 - operating system : Linux - PHP version : 8.1.2 - GD version : 2.2.4 - supported image types : png webp jpg gif bmp - open_basedir : /var/customers/webs/test3:/var/customers/tmp/test3:/usr/share/php:/usr/share/php5:/tmp - upload_max_filesize : 64M (67108864 bytes) - language : de_DE source is an uploaded file - upload OK - file name OK determining MIME type - Fileinfo PECL extension deactivated - checking MIME type with UNIX file() command PHP exec() function is disabled - checking MIME type with mime.magic file (mime_content_type()) MIME type detected as application/encrypted by mime_content_type() - MIME validated as application/encrypted source variables - you can use all these before calling process() file_src_name : GAR_Datenbank_aktuell_2022_10_10_NEW.xlsx file_src_name_body : GAR_Datenbank_aktuell_2022_10_10_NEW file_src_name_ext : xlsx file_src_pathname : /var/customers/tmp/test3/phppuQ5QX file_src_mime : application/encrypted file_src_size : 415232 (max= 67108864) file_src_error : 0 process file to /var/customers/webs/test3/dskom/media/uploaders_649615/71/in/ - file size OK - MIME type and/or extension is not allowed ! - error: Falscher Dateityp.Reply
Your PHP setup doesn't allow exec(), so you cannot use the Unis file command. And the next available method is mime.magic, but here again your file is detected as application/encrypted.
You need to set up your OS so that MIME detection returns something more meaningful for your files.Reply
Removed exec from php configuration but result is still the same-> upload failed. I suppose the files are corrupt or something inside the files prevent the correct upload, may some filters or entries etc. As upload succeeded with xlsx files created on my own there is no need for further investigations. Thank you for quick answering and help, I appreciate your work.Reply
Sorry for bothering but I didn't find any solution for my problem with some uploads. I started a new test-envirenment on another server but upload fails again with some files. I suppose that it has to do with "Mime validated as encrypted files". You wrote "You need to set up your OS so that MIME detection returns something more meaningful for your files." What can I do to ensure this?Reply
Thanks for reply. What is irritating me so much is, that upload of xlsx files and xls files generally work, so I suppose it depends of the files themselves, that cannot be uploaded. I will now try to compare files from the same customer that work with those who are not working, though I don't have any clue where to look at...Reply
Yes, it seems that it depends on the file. For instance, if the XLS file is encrypted, then the MIME is application/encrypted, which is then difficult to single out to allow only XLSX files rather than all encrypted files...Reply
Yepp, after testing a lot I am sure it depends on the files only. Tere must be something in the settings of my customers, that let the class detect them as encrypted though they are not encrypted. A simple "save as" on my system let the calls detect the as spreadsheet or other file that makes them uploadable. So my customer has to search....Reply
I tried to upload various files and xls and xlsx files failed while doc and docx files succeeded. I have an array
(only extraction, there are some more).
My logfile says:
system information
- class version : 30/08/2022
- operating system : Linux
- PHP version : 8.1.2
- GD version : 2.2.4
- supported image types : png webp jpg gif bmp
- open_basedir : /var/customers/webs/test3:/var/customers/tmp/test3:/usr/share/php:/usr/share/php5:/tmp
- upload_max_filesize : 64M (67108864 bytes)
- language : de_DE
source is an uploaded file
- upload OK
- file name OK
determining MIME type
- checking MIME type with Fileinfo PECL extension
MAGIC path will not be used
MIME type detected as application/encrypted; charset=binary by Fileinfo PECL extension
- MIME validated as application/encrypted
source variables
- you can use all these before calling process()
file_src_name : GAR_Datenbank_aktuell_2022_10_10_RAY.xls
file_src_name_body : GAR_Datenbank_aktuell_2022_10_10_RAY
file_src_name_ext : xls
file_src_pathname : /var/customers/tmp/test3/phprKRUn8
file_src_mime : application/encrypted
file_src_size : 415232 (max= 67108864)
file_src_error : 0
process file to /var/customers/webs/test3/dskom/media/uploaders_649615/71/in/
- file size OK
- MIME type and/or extension is not allowed !
- error: Falscher Dateityp.
What am I doing wrong?
it reads
->allowed = array(
I created myself files .xlsx and .xls and upload works fine.
Is it possible that the customer files are corrupt in some way though the file obviously opens and reads fine?
You may try to deactivate FileInfo in order to rely instead on Unix file command: deactivate the code using fileinfo in the class. Search for this line in the class:
And replace it with
system information
- class version : 30/08/2022
- operating system : Linux
- PHP version : 8.1.2
- GD version : 2.2.4
- supported image types : png webp jpg gif bmp
- open_basedir : /var/customers/webs/test3:/var/customers/tmp/test3:/usr/share/php:/usr/share/php5:/tmp
- upload_max_filesize : 64M (67108864 bytes)
- language : de_DE
source is an uploaded file
- upload OK
- file name OK
determining MIME type
- Fileinfo PECL extension deactivated
- checking MIME type with UNIX file() command
PHP exec() function is disabled
- checking MIME type with mime.magic file (mime_content_type())
MIME type detected as application/encrypted by mime_content_type()
- MIME validated as application/encrypted
source variables
- you can use all these before calling process()
file_src_name : GAR_Datenbank_aktuell_2022_10_10_NEW.xlsx
file_src_name_body : GAR_Datenbank_aktuell_2022_10_10_NEW
file_src_name_ext : xlsx
file_src_pathname : /var/customers/tmp/test3/phppuQ5QX
file_src_mime : application/encrypted
file_src_size : 415232 (max= 67108864)
file_src_error : 0
process file to /var/customers/webs/test3/dskom/media/uploaders_649615/71/in/
- file size OK
- MIME type and/or extension is not allowed !
- error: Falscher Dateityp.
You need to set up your OS so that MIME detection returns something more meaningful for your files.
I thought allow exec() would be a risk?!
So I can remove it from the array.
I suppose the files are corrupt or something inside the files prevent the correct upload, may some filters or entries etc.
As upload succeeded with xlsx files created on my own there is no need for further investigations.
Thank you for quick answering and help, I appreciate your work.
I suppose that it has to do with "Mime validated as encrypted files". You wrote "You need to set up your OS so that MIME detection returns something more meaningful for your files."
What can I do to ensure this?
I tried with two XLSX files on my system:
Here, even though they are two XLSX files, the MIME returned is not the same. So it seems that the file itself may confuse the MIME type detection.
I am not too sure that we can do something about that...
What is irritating me so much is, that upload of xlsx files and xls files generally work, so I suppose it depends of the files themselves, that cannot be uploaded.
I will now try to compare files from the same customer that work with those who are not working, though I don't have any clue where to look at...
A simple "save as" on my system let the calls detect the as spreadsheet or other file that makes them uploadable.
So my customer has to search....