simcoweb Posted December 21, 2007 Share Posted December 21, 2007 I'm doing a simple file upload with some modest validation parameters. I thought I had this down but I get this error message when using this code: // let's do some validation for file type if(isset($_POST['submitted'])){ $file_type = array(gif, jpg); $file_upload = $_FILES['uploadedfile']['type']; $max_size = "100000"; // create an error message array $errors = array(); if(!in_array($file_type)) { $errors[] = "The file type you have attempted to upload is not the proper format. Only .jpg or .gif files are allowed."; exit; } if($_FILES['uploadedfile']['size'] > $max_size) { $errors[] = "The file size is too large. Reduce the number of bytes below $max_size and try again"; exit; } else { $target_path = "images/clients/"; // add target path and file name $target_path = $target_path . basename($_FILES['uploadedfile']['name']); // get temporary name $temp_name = $_FILES['uploadedfile']['temp_name']; // let's move the file to permanent home if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded<br>"; } else { $errors[] = "Something went wrong with the upload. Please try again.<br> "; } // end of else statement } // end of if submitted statement } ?> Error message is: Wrong parameter count for in_array() Quote Link to comment https://forums.phpfreaks.com/topic/82609-error-message-with-array/ Share on other sites More sharing options...
phpSensei Posted December 21, 2007 Share Posted December 21, 2007 It needs 2 values, one for the string, and one for the array bool in_array ( mixed $needle , array $haystack [, bool $strict ] ) <?php $string = "hello"; $list = array('hello','bye','good morning'); if(in_array($string,$list)){ echo 'Hello is in the array'; } else { echo 'not found in array'; } ?> Try if(!in_array($file_upload,$file_type)) { $errors[] = "The file type you have attempted to upload is not the proper format. Only .jpg or .gif files are allowed."; exit; } Quote Link to comment https://forums.phpfreaks.com/topic/82609-error-message-with-array/#findComment-420080 Share on other sites More sharing options...
simcoweb Posted December 21, 2007 Author Share Posted December 21, 2007 That god rid of the php error, but the image upload is producing errors: # The file type you have attempted to upload is not the proper format. Only .jpg or .gif files are allowed. # Something went wrong with the upload. Please try again. Even though i've tried both .gif and .jpg neither uploads. BUT, if I try uploading a .doc file it does upload but still throws the error that only .gif or .jpg files can be uploaded. Totally confused. Quote Link to comment https://forums.phpfreaks.com/topic/82609-error-message-with-array/#findComment-420234 Share on other sites More sharing options...
PFMaBiSmAd Posted December 21, 2007 Share Posted December 21, 2007 When you have a comparison in your code that fails, you need to display what the actual values being compared are so that you can see why the comparison failed. The ['type'] element for .gif and .jpg files can be any of the following - "image/gif", "image/jpeg", "image/pjpeg" Ref: http://www.w3schools.com/media/media_mimeref.asp Quote Link to comment https://forums.phpfreaks.com/topic/82609-error-message-with-array/#findComment-420395 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.