Jump to content

Can not limit file type in uploads.


dvdljns

Recommended Posts

I am trying to write a file upload script. It uploads files just fine now it is time to limit the type of file uploaded. here is the code I am trying to use.

if (!($uploaded_type="archive/zip")) {
echo "You may only upload zip files.<br>";
$ok=0;
} 

 

This is the first php script I have wrote and thought I understood what I was doing but what happens is it uploads the file then tells you it uploaded ok then tells you it can only upload zip files. I want only compressed files uploaded. how do I do this.

 

Link to comment
Share on other sites

The type sent for a zip file is different depending on the browser used. Here's what I get for the following browsers I tested with:

Chrome v4.1.249.1064:

Array
(
    [userfile] => Array
        (
            [name] => 0_to_99_markers.zip
            [type] => application/octet-stream
            [tmp_name] => D:\xampp\xampp\tmp\php1DA7.tmp
            [error] => 0
            [size] => 161036
        )

)

 

Firefox v3.6.3:

Array
(
    [userfile] => Array
        (
            [name] => 0_to_99_markers.zip
            [type] => application/zip
            [tmp_name] => D:\xampp\xampp\tmp\phpE5D6.tmp
            [error] => 0
            [size] => 161036
        )

)

MSIE8

Array
(
    [userfile] => Array
        (
            [name] => 0_to_99_markers.zip
            [type] => application/x-zip-compressed
            [tmp_name] => D:\xampp\xampp\tmp\php8273.tmp
            [error] => 0
            [size] => 161036
        )

)

 

Opera v10.53

Array
(
    [userfile] => Array
        (
            [name] => 0_to_99_markers.zip
            [type] => application/zip
            [tmp_name] => D:\xampp\xampp\tmp\php117A.tmp
            [error] => 0
            [size] => 161036
        )

)

 

Ken

Link to comment
Share on other sites

I thought it was decide by the os I never thought of checking to see what the browser was sending thanks. Let me try it with the new info. :confused:

 

How was it done on here does anybody know. this would be something like I am looking for.

 

Allowed file types: zip,bz,gz,tar.

 

 

 

Link to comment
Share on other sites

I thought it was decide by the os I never thought of checking to see what the browser was sending thanks. Let me try it with the new info. :confused:

 

How was it done on here does anybody know. this would be something like I am looking for.

 

Allowed file types: zip,bz,gz,tar.

Dont validate by mime instead validate by extracting the extension from $_FILES['file']['name']

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.