Hello friends, This is my website - Snapsvilla Its a image uploading website... I allow users to upload there jpeg, gif, and bmp snaps. If a user uploads a snap which does not belong to these three extension it will show "Unsupported file format"... There seems to be a problem because whenever user uploads a snap clicked from DIGITAL CAM, it shows "unsupported file format" but the file is of JPEG formant.. When I upload the snaps clicked from mobile then it works fine.. Am unable to locate the problem with my code... Please suggest... $name1 = $_FILES['snap1']['name']; $size1 = $_FILES['snap1']['size']; $type1 = $_FILES['snap1']['type']; $temp1 = $_FILES['snap1']['tmp_name']; $error1 = $_FILES['snap1']['error']; if($name1) { if($size1 <= 5000000) { if($type1 == 'image/jpeg' || $type1 == 'image/pjpeg' || $type1 == 'image/gif' || $type1 == 'image/bmp' || $type1 == 'image/png') { $save_as = $name1; $location = "uploadedsnaps/".$save_as; move_uploaded_file($temp1,$location); $album_snap = mysql_query("SELECT * FROM snaps WHERE albumid='$albumid'"); $album_rows = mysql_num_rows($album_snap); if($abum_rows == 0) { $album_dp = mysql_query("UPDATE album SET cover='$location' WHERE albumid='$albumid'"); } $entry = mysql_query("INSERT INTO snaps VALUES('','$userid','$albumid','$serialid','$save_as','$name1','','$size1','$type1','$day')") or die(mysql_error()); $avail = mysql_query("SELECT * FROM snaps WHERE albumid='$albumid' AND snapname='$name1' AND userid='$userid' ORDER BY albumid DESC"); $avail = mysql_fetch_assoc($avail); $sd = $avail['snapid']; $availability = mysql_query("INSERT INTO snapsavailability VALUES ('','$sd','$albumid','yes','no')"); } else header("location:upload.php?z=Couldnt upload file. Unsuitable file format. "); } header("location:displayalbum.php?aid=$albumid"); } PHP:
Have you tried to print $_FILES['snap1']['type']; when the error occurs? Is the output of $_FILES['snap1']['type']; one of your options?
I have tried that and the output was JPEG format. Yes.. I'm using it to identify the type of file and then checking if the type is suitable for uploading or not. If it is not suitable format then it ll displays a message "Unsuitable file format"
It looks to me like it displays a message: Couldnt upload file. Unsuitable file format. When $name1 is not set? if($name1) { // code } else header("location:upload.php?z=Couldnt upload file. Unsuitable file format. "); PHP: There is no else on the if($type1 == 'image/jpeg' || $type1 == ...... bit? Just a thought...... ps. i have been up all night coding....so I could just be going nuts! Have a good day everyone! zzzz
No that is not the case... it will be zero only if user wants 2 create a new album.. if he wants to upload snaps in existing album then it will not be 0 but 1...
DO NOT! rely on MIME-Type, use pathinfo() on the $_FILES['file']['name'] to retrieve the extension...