takn25 Posted April 18, 2011 Share Posted April 18, 2011 Hi, I am having trouble with some GIF, PNG images the error I am receiving these errors imagecreatefromgif() [function.imagecreatefromgif]: '/tmp/phpNAhLPI' is not a valid GIF and a similar one for PNG Is there a solution to this? and How can I hide these errors? So they never display to the user and Instead I echo a user friendly error. Please note again this is happening with some GIF and PNGs not all of them. Appreciate any help and thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/234004-why-is-this-happening-and-what-is-the-solution/ Share on other sites More sharing options...
.josh Posted April 18, 2011 Share Posted April 18, 2011 The problem is on line 42 Quote Link to comment https://forums.phpfreaks.com/topic/234004-why-is-this-happening-and-what-is-the-solution/#findComment-1202774 Share on other sites More sharing options...
takn25 Posted April 18, 2011 Author Share Posted April 18, 2011 Where did you come up with that? 42? Quote Link to comment https://forums.phpfreaks.com/topic/234004-why-is-this-happening-and-what-is-the-solution/#findComment-1202776 Share on other sites More sharing options...
Skewled Posted April 18, 2011 Share Posted April 18, 2011 Is there a solution to this? and How can I hide these errors? So they never display to the user and Instead I echo a user friendly error. Please note again this is happening with some GIF and PNGs not all of them. In my experience: 1. Can't help without seeing your code. 2. You can't unless you supress them in php.ini display_errors and are happy with loading a blank page. 3. You can't echo a friendly error if there is a parse error. What are the differences between the GIF's that work and do not work? Are you validating they are actual GIFs or PNG files? Quote Link to comment https://forums.phpfreaks.com/topic/234004-why-is-this-happening-and-what-is-the-solution/#findComment-1202777 Share on other sites More sharing options...
takn25 Posted April 18, 2011 Author Share Posted April 18, 2011 Sorry My bad for not posting the code and about them being or not being a valid GIF when checked through window and stuff it shows they are a GIF and a PNG FILE format no problem here. Then If i recall one of my friends used an image resizer to resize the dimensions. Fine till here but my concern is if one of the users used some sort of image resizer and has the same problem which I am facing currently is there anyway I can tackle this in a user friendly manner. Code is below cheers! $type=$_FILES["myfile"]["type"]; $file_error=$_FILES["myfile"]["error"]; $file_size=$_FILES["myfile"]["size"]; $tmp_name = $_FILES['myfile']['tmp_name']; $name=$_FILES["myfile"]["name"]; if ($file_error>0) { die (header("LOCATION: editprofile.php")); } if ($type!="image/png" && $type!="image/jpeg" && $type != "image/gif") { die (header("LOCATION: editprofile.php?ed=picture&error=1013"));} if ($file_size>=1048577) { die (header("LOCATION: editprofile.php?ed=picture&error=1014"));} if ($_POST['uploadpic']) { if ($name && $type=="image/jpeg") { // Set a maximum height and width $width = 181; $height = 120; // Content type // Get new dimensions list($width_orig, $height_orig) = getimagesize($tmp_name); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } // Resample $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($tmp_name); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); $location="profiles/$myid/$name"; // Output imagejpeg($image_p, $location, 100); $query =mysql_query ("UPDATE finxed_users SET avatar='$location' WHERE id='$myid'"); die (header ("LOCATION: editprofile.php?ed=picture")); }// end jpeg if ($name && $type=="image/png") { // Set a maximum height and width $width = 181; $height = 120; // Content type // Get new dimensions list($width_orig, $height_orig) = getimagesize($tmp_name); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } // Resample $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefrompng ($tmp_name); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); $location="profiles/$myid/$name"; // Output imagepng($image_p, $location, 9); $query =mysql_query ("UPDATE users SET avatar='$location' WHERE id='$myid'"); header ("LOCATION: editprofile.php?ed=picture"); }// end png if ($name && $type=="image/gif") { // Set a maximum height and width $width = 181; $height = 120; // Content type // Get new dimensions list($width_orig, $height_orig) = getimagesize($tmp_name); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } // Resample $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromgif($tmp_name); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); $location="profiles/$myid/$name"; // Output imagegif($image_p, $location, 100); $query =mysql_query ("UPDATE users SET avatar='$location' WHERE id='$myid'"); header ("LOCATION: editprofile.php?ed=picture"); }// end gif } Quote Link to comment https://forums.phpfreaks.com/topic/234004-why-is-this-happening-and-what-is-the-solution/#findComment-1202782 Share on other sites More sharing options...
Skewled Posted April 18, 2011 Share Posted April 18, 2011 Does it work and Firefox and not IE? Quote Link to comment https://forums.phpfreaks.com/topic/234004-why-is-this-happening-and-what-is-the-solution/#findComment-1202785 Share on other sites More sharing options...
takn25 Posted April 18, 2011 Author Share Posted April 18, 2011 No the error is being produced in all browsers. I am kinda having the idea its due to not being a genuine PNG or GIF thanks to the resizer but its an awful error. I just wanna get rid of it some how :/. Quote Link to comment https://forums.phpfreaks.com/topic/234004-why-is-this-happening-and-what-is-the-solution/#findComment-1202791 Share on other sites More sharing options...
Skewled Posted April 18, 2011 Share Posted April 18, 2011 <?php $filename = "/usr/local/something.txt"; echo $finfo->file($filename); ?> Upload one of the GIF's in question and change the path above to the image. Then run the script and it will return the MIME type of the file. If it returns jpeg for a gif then the resizer is replacing the header information on the gif image, and making it a jpeg. From there you could do some error checking and alert the user that the file type didn't match the file extension. Quote Link to comment https://forums.phpfreaks.com/topic/234004-why-is-this-happening-and-what-is-the-solution/#findComment-1202793 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.