File extension .txt being added

See all posts Reply

File extension .txt being added new!
by Tony, 14 years, 5 months ago
I'm trying to allow HTML files to be uploaded, and I've added a check to ensure that only HTML files are uploaded.

But every time I upload one, it is getting the .txt extension added. I've tried setting no_script to false, but when I do this I then get an 'Incorrect file type' error for any file that I try to upload.

Here's the code;
$newmenu = new upload($_FILES['menu_file']);
if ($newmenu->uploaded) {
  if ($newmenu->file_src_mime != 'text/html') {
    die('Error: Error Message' . $newmenu->clean());
  } else {
    $newmenu->file_auto_rename = false;
    $newmenu->file_safe_name = true;
    $newmenu->file_overwrite = true;
    $newmenu->no_script = false;
    $newmenu->process('../menus/');
    if ($newmenu->processed) {
      echo 'File Uploaded';
    } else {
      echo 'error : ' . $newmenu->error;
    }
  }
}
Reply
Re: File extension .txt being added new!
by colin, 14 years, 5 months ago
You need to allow the MIME type for the HTML files:
$newmenu->no_script = false;
$newmenu->allowed[] = 'text/html';

Or, if you want to only allow HTML files:
$newmenu->no_script = false;
$newmenu->allowed = array('text/html');
Reply
Re: File extension .txt being added new!
by Tony, 14 years, 5 months ago
That's great. Thanks for your help.Reply