trouble uploading a mht file

See all posts Reply

trouble uploading a mht file new!
by ric woods, 15 years, 2 months ago
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 '  file uploaded with success';
  } 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


Any suggestions will be appreciated.

ThanksReply
Re: trouble uploading a mht file new!
by colin, 15 years, 2 months ago
You need to add the corresponding MIME type to the list of allowed MIME types.

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():
$handle->allowed[] = 'message/rfc822';
Reply
Re: trouble uploading a mht file new!
by ric woods, 15 years, 2 months ago
thanks Colin, it worked great
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
$uploaded->allowed[] = mime_content_type($uploaded->file_src_pathname);
but it did not work

Sorry I am relatively new to php and MIME.

Thanks

RicReply
Re: trouble uploading a mht file new!
by colin, 15 years, 2 months ago
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
Re: trouble uploading a mht file new!
by ric woods, 15 years, 2 months ago
thanks again Colin - it makes good seance. i am not familiar with MIMEReply