Jump to content

Problema a fazer upload de imagens


jcfr
 Share

Recommended Posts

mais uma vez recorro á vossa ajuda...

estou a desenvolver um projecto e tenho uma parte onde faço upload de imagens, o meu problema é o seguinte:

a aplicação faz a verificação do tipo de ficheiros e faz o respectivo upload sem problemas, mas quando tento fazer o upload de ficheiros bmp dá erro:

Warning: imagecreatefromxbm() [function.imagecreatefromxbm]: 'C:\....' is not valid XBM file in c:\.... on line 101

outro problema que tenho é com alguns ficheiros jpg, ate agora sempre funcionou, mas recentemente em alguns ficheiros jpg da o seguinte erro:

Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: recoverable error: Corrupt JPEG data: 5 extraneous bytes before marker 0xd9 in c:\.... on line 95

o codigo é o seguinte:

if (($_FILES['Photo1']['size']>0))
{ 
//***************START OF RESIZE IMAGE********************

// The file
$filename = $_FILES['Photo1']['tmp_name'];

// Set a maximum height and width
$width = 513;
$height = 385;

// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);

if ($width && ($width_orig < $height_orig)) {
   $width = ($height / $height_orig) * $width_orig;
} else {
   $height = ($width / $width_orig) * $height_orig;
}


// Resample
$image_p = imagecreatetruecolor($width, $height);


$type=$_FILES['Photo1']['type'];
echo "tipo - $type";
if(($_FILES['Photo1']['type']=="image/jpeg")||($_FILES['Photo1']['type']=="image/jpg")||($_FILES['Photo1']['type']=="image/pjpeg")||($_FILES['Photo1']['type']=="image/JPG")){
$image = imagecreatefromjpeg($filename);
}else if(($_FILES['Photo1']['type']=="image/png")||($_FILES['Photo1']['type']=="image/x-png")||($_FILES['Photo1']['type']=="image/PNG")||($_FILES['Photo1']['type']=="image/X-PNG")){
$image = imagecreatefrompng($filename);
}else if(($_FILES['Photo1']['type']=="image/gif")||($_FILES['Photo1']['type']=="image/GIF")){
$image = imagecreatefromgif($filename);
}else if($_FILES['Photo1']['type']=="image/bmp"){
$image = imagecreatefromxbm($filename);
}else{
	$msg = "ERRO: O tipo da imagem tem de ser jpg, bmp, gif ou png!";
	echo "<script langauge=\"javascript\">alert(\"".$msg."\");</script>";
	echo("<script language=\"javascript\">");
	echo("self.location.href = \"empresa/em_edit_fotos.php?cod=$cod\";");
	echo("</script>");
}


imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

// Output
if(($_FILES['Photo1']['type']=="image/jpeg")||($_FILES['Photo1']['type']=="image/jpg")||($_FILES['Photo1']['type']=="image/pjpeg")||($_FILES['Photo1']['type']=="image/JPG")){
imagejpeg($image_p, $filename, 100);
}else if(($_FILES['Photo1']['type']=="image/png")||($_FILES['Photo1']['type']=="image/x-png")||($_FILES['Photo1']['type']=="image/PNG")||($_FILES['Photo1']['type']=="image/X-PNG")){
imagepng($image_p, $filename, 100);
}else if(($_FILES['Photo1']['type']=="image/gif")||($_FILES['Photo1']['type']=="image/GIF")){
imagegif($image_p, $filename, 100);
}else if($_FILES['Photo1']['type']=="image/bmp"){
imagewbmp($image_p, $filename, 100);
}

//***************END OF RESIZE IMAGE********************

//RENAME PHOTO AND MOVE TO PROPER FOLDER
$id=rand(00000000000,99999999999);
//$id = "1";  //if multiple photos need to be named 1,2,3 etc
    
$extension = strrchr($_FILES['Photo1']['name'],'.'); 
$extension = strtolower($extension);

$save_path = 'img/'; 
    
$NewPhotoName = $id . $extension;

$filenameum = $save_path . $id . $extension;
$file_exist=0;
while($file_exist==0){
if (file_exists($filenameum)) {
   $id=rand(0000000000,99999999999);
   $filenameum = $save_path . $id . $extension;
} else {
   $file_exist=1;
}
}
move_uploaded_file($_FILES['Photo1']['tmp_name'],$filenameum);
$minium = "img/minis/$NewPhotoName";
geraThumb("$filenameum","$minium",110);


$errors = 0;
	$msg = "Imagem enviada com sucesso!";
	echo "<script langauge=\"javascript\">alert(\"".$msg."\");</script>";
}else{
	$msg = "Caminho da imagem errado!";
	echo "<script langauge=\"javascript\">alert(\"".$msg."\");</script>";

}

se alguem me poder ajudar agradecia

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. 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.