Jump to content

Why is this happening and what is the solution?


takn25

Recommended Posts

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!

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?

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 



}

 

 

<?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.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.