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
https://forums.phpfreaks.com/topic/200932-can-not-limit-file-type-in-uploads/
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

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.

 

 

 

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']

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.