dvdljns Posted May 6, 2010 Share Posted May 6, 2010 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. Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 6, 2010 Share Posted May 6, 2010 Use double equals for comparison. A single equal sign is used for assignment Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 6, 2010 Share Posted May 6, 2010 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 Quote Link to comment Share on other sites More sharing options...
dvdljns Posted May 6, 2010 Author Share Posted May 6, 2010 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. 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. Quote Link to comment Share on other sites More sharing options...
newbtophp Posted May 6, 2010 Share Posted May 6, 2010 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. 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'] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.