Upload xlsx files

See all posts Reply

Upload xlsx files new!
by Ray, 2 years, 1 month ago
Hi there,
I tried to upload various files and xls and xlsx files failed while doc and docx files succeeded. I have an array
$allowed = array(
  'application/pdf','application/vnd.ms-excel',
  'application/zip','application/msword',
  'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
);
(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?Reply
Re: Upload xlsx files new!
by Ray, 2 years, 1 month ago
correction:
it reads
->allowed = array(Reply
Re: Upload xlsx files new!
by Ray, 2 years, 1 month ago
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
Re: Upload xlsx files new!
by colin, 2 years, 1 month ago
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:
$this->mime_fileinfo            = true;
And replace it with
$this->mime_fileinfo            = false;
Reply
Re: Upload xlsx files new!
by Ray, 2 years, 1 month ago
I set mime_fileinfo to false, upload failed

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
Re: Upload xlsx files new!
by colin, 2 years, 1 month ago
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
Re: Upload xlsx files new!
by Ray, 2 years, 1 month ago
Thanks for info.
I thought allow exec() would be a risk?!
So I can remove it from the array.Reply
Re: Upload xlsx files new!
by Ray, 2 years, 1 month ago
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
Re: Upload xlsx files new!
by Ray, 2 years ago
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
Re: Upload xlsx files new!
by colin, 2 years ago
Basically, the MIME detection on your system returns the wrong MIME type, or more precisely not the best MIME type for your file.

I tried with two XLSX files on my system:
$ file -b --mime foo.xlsx
application/octet-stream; charset=binary

$ file -b --mime bar.xlsx
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=binary

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...Reply
Re: Upload xlsx files new!
by Ray, 2 years ago
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
Re: Upload xlsx files new!
by colin, 2 years ago
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
Re: Upload xlsx files new!
by Ray, 2 years ago
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