Page 1 of 1

.zip mimetype

Posted: Thu Oct 30, 2003 7:43 pm
by DuFF
Ok, I have a script that uploads a file but before doing that it makes sure that the file is a .zip file by comparing the mimetype. I get the mimetype of the file using the code:

Code: Select all

<?php
$filetype=$_FILES['userfile']['type'];
?>
and then I run it through:

Code: Select all

<?php
if (!$error_message){
        if ($filetype == "application/zip"){
        $extension=".zip";
        }
        if ($filetype == "application/x-zip-compressed"){
        $extension=".zip";
        }
        else{
        $error_message="Upload failed. Please upload files only with the extension .zip.  This file's MIME type was $filetype.";
        }

//...

if ($error_message){
die ($error_message);
}

?>
But heres the catch, it outputs the error message: "Upload failed. Please upload files only with the extension .zip. This file's MIME type was application/zip." If $filetype is coming out as application/zip then why is the if statement not true!?! I checked the spelling and it's spelled right, but it's not working. :cry:
Please help, I'm going crazy 8O .

Posted: Thu Oct 30, 2003 8:03 pm
by Gen-ik
Where's this first $error_message coming from?

Code: Select all

if (!$error_message){ // <<<-------- THIS ONE
        if ($filetype == "application/zip"){ 
        $extension=".zip";

Posted: Thu Oct 30, 2003 8:07 pm
by DuFF
Originally from nowhere but I added a

Code: Select all

<?php
$error_message="";
?>
and nothing changed. Even tried adding NULL as its value.

EDIT:
I even took it out and no change.

Posted: Thu Oct 30, 2003 8:15 pm
by Gen-ik
Try this.........

Code: Select all

<?php
if(isset($filetype))
{
    if($filetype == "application/zip")
    { 
        $extension=".zip"; 
    } 
    else if($filetype == "application/x-zip-compressed")
    { 
        $extension=".zip"; 
    } 
    else
    { 
        $error_message="Upload failed. Please upload files only with the extension .zip.  This file's MIME type was $filetype."; 
    } 
}

//... 

if ($error_message) die ($error_message);

?>

Posted: Thu Oct 30, 2003 8:29 pm
by DuFF
Thanks a lot. I don't know why it wasn't working though, it used to worked on my tripod.co.uk site but not this one.