Warptweet Posted December 24, 2006 Share Posted December 24, 2006 I know this has been easily done many times...And I've even read the file upload tutorials, BUT.... I don't know WHERE in this code to put it...What code do I put in, and WHERE do I put the code in, to make it so that the only file types allowed to be uploaded on this code are .gm6,.gm5, .gmd, and .exe?So basically, where do I put a code for making file restrictions?CODE:[sub]<html><head><title>Warptweet.com - Uploader</title><style type="text/css"><!--body {background-color: black; color: white;}a {color: white;}a:hover {font-size: 110%;}--></style></head><body><div align="center"><fieldset><legend>Warptweet.com File Upload</legend><?phpif ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; }else { echo "Filename: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; }if (file_exists("filer/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "filer/" . $_FILES["file"]["name"]); echo "Stored in: " . "http://www.warptweet.com/wh/filer/" . $_FILES["file"]["name"]; }?><center><a href="index.htm"><--Back Home</a></center></body></html>[/sub] Link to comment https://forums.phpfreaks.com/topic/31780-file-upload-add-file-restriction-please/ Share on other sites More sharing options...
ShiVer Posted December 25, 2006 Share Posted December 25, 2006 Try this[code]<html><head><title>Warptweet.com - Uploader</title><style type="text/css"><!--body {background-color: black; color: white;}a {color: white;}a:hover {font-size: 110%;}--></style></head><body><div align="center"><fieldset><legend>Warptweet.com File Upload</legend><?php$allowed_files = array( '.ext1', '.ext2', '.ext3' // Change these to match what you want); if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . " "; } else { echo "Filename: " . $_FILES["file"]["name"] . " "; echo "Type: " . $_FILES["file"]["type"] . " "; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb "; } if (file_exists("filer/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { if(in_array(substr($_FILES["file"]["name"], -1, 4), $allowed_files)) { move_uploaded_file($_FILES["file"]["tmp_name"], "filer/" . $_FILES["file"]["name"]); echo "Stored in: " . "http://www.warptweet.com/wh/filer/" . $_FILES["file"]["name"]; } }?><center><a href="index.htm"><--Back Home</a></center></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/31780-file-upload-add-file-restriction-please/#findComment-147445 Share on other sites More sharing options...
Warptweet Posted December 25, 2006 Author Share Posted December 25, 2006 Sorry, but that does not work!Could you or somebody else please try again?I know, I know, this is supposed to be really simple... I'm just confused on what place in the code to put a code at all..... :'( Link to comment https://forums.phpfreaks.com/topic/31780-file-upload-add-file-restriction-please/#findComment-147656 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.