.zip mimetype

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

.zip mimetype

Post 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 .
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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";
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post 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.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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);

?>
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post 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.
Post Reply