Hi I have an image upload that works fine for me (FF and IE) - but users often tell me doesn't work for them. I don't think it's filesize related because when I ask them to email the files they are usually pretty small. Am I missing something obvious, or is there a more reliable way to handle file uploads? $allowed_pics = array('image/jpeg', 'image/jpg', 'image/pjpeg'); if(is_uploaded_file($_FILES['image1']['tmp_name'])){ if(in_array($_FILES['image1']['type'], $allowed_pics)) { $field1_filename = "file1_".date("sihdmY").".jpg"; if(!move_uploaded_file($_FILES['image1']['tmp_name'], "./files/".$field1_filename)){ die("File " . $_FILES['image1']['name'] . " Image 1 was not uploaded."); } } } Code (markup): I use the same code 8 times on the page (with different filenames) so that up to 8 pictures can be uploaded at once. Thanks for any help or suggestions!
You can add more condition for image size limitation and for upload error. add this conditions in ur code.... //to check the file size is not more then 100000 byte if($_FILES["file"]["size"] < 100000)) { } //this condition for any error if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; }
Check you have set the form in html as application/multipart instead of post/get and also check you are giving the correct file field name there in your php code
Thanks for the suggestions... Is there any difference between 'application/multipart' and enctype='multipart/form-data' (which I currently use) ? I'd ignored error messages because I can't recreate the errors here, but you've got me thinking - perhaps something like if ($_FILES["file"]["error"] > 0) {mail (.,.,.);} with the error being mailed to me, would help me work it out cheers
There are differences between application/multipart and multipart/form-data but for this script both should do. So this is not an issue. If everything is same for you and your clients' codes, then it must run. However, your server and their server may contain a basic difference. Mime type JPEG may be blocked on their server (for whom, the script is not working), though it's an odd case.
thanks techbongo, I had wondered if I should change it to look at mime types with the word 'image' in them instead of specifying jpg etc - problem is I only want jpg files because they then go through a resizing routine etc. Shame if people can't upload jpg files...