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.
I am trying to upload a mht file (Powerpoint presentation) using class.upload.php
my code which works for pdf and images files is:
$uploaded = new Upload($_FILES['uploadnew']);
$uploaded->Process('./resources/');
if ($uploaded->uploaded) {
if ($uploaded->processed) {
echo ' ';
} else {
echo ' Error: ' . $uploaded->error . '';
}
}
I get the error Error: Incorrect type of file.
the log file is: system information - GD version : 2.0.34 - supported image types : png jpg gif bmp - open_basedir : no restriction - language : en_GB source is an uploaded file - upload OK - file name OK - source variables file_src_name : ontarioworkerco-opspres.mht file_src_name_body : ontarioworkerco-opspres file_src_name_ext : mht file_src_pathname : C:\xampp\tmp\php119.tmp file_src_mime : message/rfc822 file_src_size : 2107870 (max= 33554432) file_src_error : 0 process file to ./resources/\ - file size OK
Error: Incorrect type of file.
system information - GD version : 2.0.34 - supported image types : png jpg gif bmp - open_basedir : no restriction - language : en_GB source is an uploaded file - upload OK - file name OK - source variables file_src_name : ontarioworkerco-opspres.mht file_src_name_body : ontarioworkerco-opspres file_src_name_ext : mht file_src_pathname : C:\xampp\tmp\php119.tmp file_src_mime : message/rfc822 file_src_size : 2107870 (max= 33554432) file_src_error : 0 process file to ./resources/\ - file size OK
No, you cannot do what you did, as file_src_pathname is set after allowed is read.
For security reason, MIME types are limited to what you allow only. So you have an array of allowed MIME types in allowed, and you can add some as you did with message/rfc822.
You can allow everything, but it is dangerous, so I wouldn't recommend it. To allow everything, use:
$uploaded->allowed = array('*/*');
You can then later add some dangerous MIME types in forbidden to explicitly prevent your users to upload some dangerous files.Reply
my code which works for pdf and images files is:
I get the error
Error: Incorrect type of file.
the log file is:
system information
- GD version : 2.0.34
- supported image types : png jpg gif bmp
- open_basedir : no restriction
- language : en_GB
source is an uploaded file
- upload OK
- file name OK
- source variables
file_src_name : ontarioworkerco-opspres.mht
file_src_name_body : ontarioworkerco-opspres
file_src_name_ext : mht
file_src_pathname : C:\xampp\tmp\php119.tmp
file_src_mime : message/rfc822
file_src_size : 2107870 (max= 33554432)
file_src_error : 0
process file to ./resources/\
- file size OK
Error: Incorrect type of file.
system information
- GD version : 2.0.34
- supported image types : png jpg gif bmp
- open_basedir : no restriction
- language : en_GB
source is an uploaded file
- upload OK
- file name OK
- source variables
file_src_name : ontarioworkerco-opspres.mht
file_src_name_body : ontarioworkerco-opspres
file_src_name_ext : mht
file_src_pathname : C:\xampp\tmp\php119.tmp
file_src_mime : message/rfc822
file_src_size : 2107870 (max= 33554432)
file_src_error : 0
process file to ./resources/\
- file size OK
Any suggestions will be appreciated.
Thanks
Here, you log shows that the file you try to upload has a MIME type which is message/rfc822
For instance, add it to the allowed parameter of the class, before you call process():
but, as usual another question
the site this is for will be updated by non-technical staff.
Is there a way the MIME type can be automatically determined?
i tried
but it did not work
Sorry I am relatively new to php and MIME.
Thanks
Ric
For security reason, MIME types are limited to what you allow only. So you have an array of allowed MIME types in allowed, and you can add some as you did with message/rfc822.
You can allow everything, but it is dangerous, so I wouldn't recommend it. To allow everything, use:
You can then later add some dangerous MIME types in forbidden to explicitly prevent your users to upload some dangerous files.