verot / class.upload.php

This PHP class uploads files and manipulates images very easily. It is in fact as much as an image processing class than it is an upload class. Compatible with PHP 4, 5, 7 and 8. Supports processing of local files, uploaded files, files sent through XMLHttpRequest.
http://www.verot.net/php_class_upload.htm
GNU General Public License v2.0
853 stars 359 forks source link

Xls files saving with .txt extension #98

Closed Lovattows closed 6 years ago

Lovattows commented 6 years ago

Hello everyone, i'm trying to upload some files with .xls extension, and inside my folder they are saving that .xls files with .txt extension. Need advice please.

verot commented 6 years ago

Check out the log produced by the class. Probably there is an issue while detecting MIME types. Please read the documentation accordingly.

Lovattows commented 6 years ago

Log output this: system information

verot commented 6 years ago

I see... So basically, you are (as per the log) uploading a file with no extension. The class detects the MIME as being application/vnd.ms-office

But, because of the option no_script, because there is no file extension, the class tries to add the correct extension. In the list of supported MIME types, application/vnd.ms-office is not present (we have application/vnd.ms-excel for XLS files), and so it adds the extension .txt.

You can try to deactivate the option no_script to prevent this behaviour. But in fact, your upload should send the correct file name and file extension (which is not the case in your log).

Alternatively, you can try to replace the MIME type for the extension XLS (so to have 'xls' => 'application/vnd.ms-office')

Lovattows commented 6 years ago

Thank you so much, added the MIME type 'xls' => 'application/vnd.ms-office' and worked as well. PS: i can add multiple xls mime_types? 'xls' => 'application/vnd.ms-excel', 'xls' => 'application/vnd.ms-office',

verot commented 6 years ago

No, you cannot add several ones, as it is a PHP indexed array. Only the last xls key will be taken into account.

Lovattows commented 6 years ago

Ok, thank you so much.