richiejones24 Posted July 27, 2011 Share Posted July 27, 2011 I am a total noob at php and am trying to write a upload script with validation the script uploads the files ok but the validation does not work any help or ideas would be much appreciated. $allowed_filetypes = array('.jpg','.gif','.bmp','.png'); //These will be the types of file that will pass the validation. $max_filesize = 1; // Maximum filesize in BYTES (currently 0.5MB). $upload_path = '../pic_upload/'; // The place the files will be uploaded to. foreach ($_FILES["pictures"]["error"] as $key => $error) { if(filesize($_FILES['pictures']['tmp_name'][$key]) > $max_filesize) // Now check the filesize, if it is too large then DIE and inform the user. die('The file you attempted to upload is too large.'); $filename = $_FILES['pictures']['name'][$key]; $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); if(!in_array($ext,$allowed_filetypes)) die('The file you attempted to upload is not allowed.'); if ($error == UPLOAD_ERR_OK) { echo"$error_codes[$error]"; move_uploaded_file($_FILES["pictures"]["tmp_name"][$key],$upload_path . $_FILES["pictures"]["name"][$key]) or die("Problems with upload"); } } Quote Link to comment https://forums.phpfreaks.com/topic/242943-my-first-upload-script-with-validation/ Share on other sites More sharing options...
cs.punk Posted July 27, 2011 Share Posted July 27, 2011 Use code tags... Quote Link to comment https://forums.phpfreaks.com/topic/242943-my-first-upload-script-with-validation/#findComment-1247839 Share on other sites More sharing options...
richiejones24 Posted July 27, 2011 Author Share Posted July 27, 2011 I do i just haven't included them on the post. Quote Link to comment https://forums.phpfreaks.com/topic/242943-my-first-upload-script-with-validation/#findComment-1247845 Share on other sites More sharing options...
richiejones24 Posted July 27, 2011 Author Share Posted July 27, 2011 ok i have the validation working now, however the script is for a multiple image upload, if you only upload 1 picture the remailing 2 field are sent blanck to the script and the validation script recognisers it as an invalid file, any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/242943-my-first-upload-script-with-validation/#findComment-1247878 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.