josiahstaggs Posted April 2, 2009 Share Posted April 2, 2009 <? if ((($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["files"]["type"] == "image/gif") || ($_FILES["files"]["type"] == "image/png")) && ($_FILES["files"]["size"] > 300000000)) { if ($_FILES["files"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; } else { if (file_exists("upload/" . $_FILES["file"]["name"])) { echo "Sorry, this file already exists on the server"; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "stored in upload/" . $_FILES["file"]["name"]; } } }//end all IFs for this loop else { echo "Only JPEG, GIF or PNG are allowed. 3mb upload limit."; } ?> Keeps returning the first echo "Only JPEG, GIF or PNG are allowed. 3mb upload limit.". Link to comment https://forums.phpfreaks.com/topic/152191-simple-upload-script-isnt-working/ Share on other sites More sharing options...
Riparian Posted April 2, 2009 Share Posted April 2, 2009 Check your variable name in the first $_FILES $_FILES["file"]["type"] == "image/jpeg") in the rest you use $_FILES["files"]............... file with an s Hope this helps Link to comment https://forums.phpfreaks.com/topic/152191-simple-upload-script-isnt-working/#findComment-799248 Share on other sites More sharing options...
josiahstaggs Posted April 2, 2009 Author Share Posted April 2, 2009 Thanks, i fixed the variable issue but i'm still getting the same result. my updated code. <? if ((($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/png")) && ($_FILES["file"]["size"] > 300000000)) { if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; } else { if (file_exists("upload/" . $_FILES["file"]["name"])) { echo "Sorry, this file already exists on the server"; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "stored in upload/" . $_FILES["file"]["name"]; } } }//end all IFs for this loop else { echo "Only JPEG, GIF or PNG are allowed. 3mb upload limit."; } ?> Link to comment https://forums.phpfreaks.com/topic/152191-simple-upload-script-isnt-working/#findComment-799916 Share on other sites More sharing options...
redarrow Posted April 2, 2009 Share Posted April 2, 2009 must be the form it a guess let see it? Link to comment https://forums.phpfreaks.com/topic/152191-simple-upload-script-isnt-working/#findComment-799921 Share on other sites More sharing options...
Riparian Posted April 2, 2009 Share Posted April 2, 2009 ($_FILES["file"]["size"] > 300000000) You are only allowing files greater than 35.7627869 megabytes to be uploaded. Should this not be < rather than > Link to comment https://forums.phpfreaks.com/topic/152191-simple-upload-script-isnt-working/#findComment-799927 Share on other sites More sharing options...
fishwild Posted April 2, 2009 Share Posted April 2, 2009 Make sure your form has the following ENCTYPE: <form enctype="multipart/form-data" id="add" name="add" method="post"> Link to comment https://forums.phpfreaks.com/topic/152191-simple-upload-script-isnt-working/#findComment-799931 Share on other sites More sharing options...
redarrow Posted April 3, 2009 Share Posted April 3, 2009 A file upload screen can be built by creating a special form which looks something like this: <!-- The data encoding type, enctype, MUST be specified as below --> <form enctype="multipart/form-data" action="__URL__" method="POST"> <!-- MAX_FILE_SIZE must precede the file input field --> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <!-- Name of input element determines name in $_FILES array --> Send this file: <input name="userfile" type="file" /> <input type="submit" value="Send File" /> </form> url http://uk.php.net/manual/en/features.file-upload.post-method.php i ask for the form but hay here it is properly formatted for uploading files Link to comment https://forums.phpfreaks.com/topic/152191-simple-upload-script-isnt-working/#findComment-799960 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.