ciao, sto facendo prove in locale per caricare delle immagini, nello specifico per convertire l'estensione (qualunque) in jpg, ma riscontro svariati problemi. Se l'immagine è jpg tutto è ok, se si tratta di gif o png ricevo questi warning:
codice:
Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\Programmi\Apache Software Foundation\Apache2.2\htdocs\prova\capitolo7\check_image.php on line 44
Warning: imagedestroy(): supplied argument is not a valid Image resource in C:\Programmi\Apache Software Foundation\Apache2.2\htdocs\prova\capitolo7\check_image.php on line 46
Warning: Cannot modify header information - headers already sent by (output started at C:\Programmi\Apache Software Foundation\Apache2.2\htdocs\prova\capitolo7\check_image.php:44) in C:\Programmi\Apache Software Foundation\Apache2.2\htdocs\prova\capitolo7\check_image.php on line 50
Warning: rename(C:/Programmi/Apache Software Foundation/Apache2.2/htdocs/prova/images/immagine.gif,C:/Programmi/Apache Software Foundation/Apache2.2/htdocs/prova/images/21.jpg) [function.rename]: File exists in C:\Programmi\Apache Software Foundation\Apache2.2\htdocs\prova\capitolo7\check_image.php on line 53
il che mi fa capire che il codice di conversione non si comporta correttamente, ma non riesco a decifrare bene i warning.
questo il codice:
Codice PHP:
$image_caption =$_POST['image_caption'];
$image_username = $_POST['image_username'];
$image_tempname = $_FILES['image_filename'] ['name'];
$today = date("Y-m-d");
$ImageDir ="C:/Programmi/Apache Software Foundation/Apache2.2/htdocs/prova/images/";
$ImageName = $ImageDir . $image_tempname;
if (move_uploaded_file($_FILES['image_filename']['tmp_name'],$ImageName)) {
list($width, $height, $type, $attr) = getimagesize($ImageName);
if ($type > 3) {
echo "Sorry, but the file you uploaded was not a GIF, JPG, or PNG file.
";
echo "Please hit your browser's 'back' button and try again.";
} else {
$insert = "INSERT INTO images
(image_caption, image_username, image_date)
VALUES
('$image_caption', '$image_username', '$today')";
$insertresults = mysql_query($insert)
or die(mysql_error());
$lastpicid = mysql_insert_id();
$newfilename = $ImageDir . $lastpicid . ".jpg";
if ($type == 2) {
rename($ImageName, $newfilename);
} else {
if (type == 1) {
$image_old = imagecreatefromgif($ImageName);
} elseif ($type == 3) {
$image_old = imagecreatefrompng($ImageName);
}
$image_jpg = imagecreatetruecolor($width, $height);
imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0, $width, $height, $width, $height);
imagejpeg($image_jpg, $newfilename);
imagedestroy($image_old);
imagedestroy($image_jpg);
}
$url = "location: showimage.php?id=" . $lastpicid;
header($url);
}
rename($ImageName, $newfilename);
}
Inoltre in un'immagine jpg che ho caricato correttamente mi ritrovo lo sfondo nero che in partenza era bianco....
grazie