spiego, ho uno script non fatto da me che serve per l'upload e resize delle immagini e funzionava.. il modulo faceva l'inserimento di tre foto ma adesso ho dovuto creare un menu con tre diverse pagine per l'inserimento di una foto per ogni pagina e non funziona più.. ad esempio se cerco di fare l'ipload e resize della foto 1 ho il seguente errore per le altre tre:
Notice: Undefined index: allegato2 in c:\programmi\easyphp1-8\www\sito\php\upload_img_big.php on line 9
Notice: Undefined index: allegato3 in c:\programmi\easyphp1-8\www\sito\php\upload_img_big.php on line 10
Notice: Undefined index: allegato2 in c:\programmi\easyphp1-8\www\sito\php\upload_img_big.php on line 13
Notice: Undefined index: allegato3 in c:\programmi\easyphp1-8\www\sito\php\upload_img_big.php on line 14
Notice: Undefined index: allegato2 in c:\programmi\easyphp1-8\www\sito\php\upload_img_big.php on line 73
Notice: Undefined index: allegato3 in c:\programmi\easyphp1-8\www\sito\php\upload_img_big.php on line 122
Notice: Undefined index: allegato2 in c:\programmi\easyphp1-8\www\sito\php\upload_img_big.php on line 178
...
il file incriminato:
<?php
$maxx = 600;
$maxy = 450;
$t=0;
$uploaddir2= 'immag/grande/';
$uploadfile1 = ($_FILES['allegato1']['name']);
$uploadfile2 = ($_FILES['allegato2']['name']);
$uploadfile3 = ($_FILES['allegato3']['name']);
copy($_FILES['allegato1']['tmp_name'], $uploadfile1);
copy($_FILES['allegato2']['tmp_name'], $uploadfile2);
copy($_FILES['allegato3']['tmp_name'], $uploadfile3);
$del_1=$uploadfile1;
$del_2=$uploadfile2;
$del_3=$uploadfile3;
$upload1_b = $uploaddir2 . $uploadfile1;
$upload2_b = $uploaddir2 . $uploadfile2;
$upload3_b = $uploaddir2 . $uploadfile3;
if (is_uploaded_file($_FILES['allegato1']['tmp_name'])){
if(file_exists($upload1_b)){
while (file_exists($upload1_b)){
$upload1_b = substr($upload1_b,0,strpos($upload1_b,"."))."_$t". strstr($upload1_b,".");
$t++;
}
list ($immag,$macchine,$uploadfile1_rn) = split ("/",$upload1_b,3);
copy($uploadfile1, $uploaddir2.$uploadfile1_rn);
$uploadfile1 = $upload1_b;
$dimensione = getimagesize($uploadfile1);
$h=$dimensione[1];
$w=$dimensione[0];
if($h > $maxx || $w > $maxy){
$source_image = imagecreatefromjpeg($uploadfile1);
list($width, $height) = getimagesize($uploadfile1);
$percent1 = $width / $maxx;
$percent2 = $height / $maxy;
$percent = max($percent1,$percent2);
$new_eight = round($height /$percent);
$new_width = round($width /$percent);
$dest_image = imagecreatetruecolor($new_width, $new_eight);
imagecopyresampled ($dest_image, $source_image, 0, 0, 0, 0, $new_width, $new_eight, $width, $height);
header("Content-type: image/jpeg");
ob_start();
imagejpeg($dest_image,$upload1_b);
}
}
else{
copy($_FILES['allegato1']['tmp_name'],$uploadfile1);
$dimensione = getimagesize($uploadfile1);
$h=$dimensione[1];
$w=$dimensione[0];
if($h > $maxx || $w > $maxy){
$source_image = imagecreatefromjpeg($uploadfile1);
list($width, $height) = getimagesize($uploadfile1);
$percent1 = $width / $maxx;
$percent2 = $height / $maxy;
$percent = max($percent1,$percent2);
$new_eight = round($height /$percent);
$new_width = round($width /$percent);
$dest_image = imagecreatetruecolor($new_width, $new_eight);
imagecopyresampled ($dest_image, $source_image, 0, 0, 0, 0, $new_width, $new_eight, $width, $height);
header("Content-type: image/jpeg");
ob_start();
imagejpeg($dest_image,$uploaddir2 . $uploadfile1);
}
}
}
if (is_uploaded_file($_FILES['allegato2']['tmp_name'])){
if(file_exists($upload2_b)){
while(file_exists($upload2_b)){
$upload2_b = substr($upload2_b,0,strpos($upload2_b,"."))."_$t". strstr($upload2_b,".");
$t++;
}
list ($immag,$macchine,$uploadfile2_rn) = split ("/",$upload2_b,3);
copy($uploadfile2, $uploaddir2.$uploadfile2_rn);
$uploadfile2 = $upload2_b;
$dimensione = getimagesize($uploadfile2);
$h=$dimensione[1];
$w=$dimensione[0];
if($h > $maxx || $w > $maxy){
$source_image = imagecreatefromjpeg($uploadfile2);
list($width, $height) = getimagesize($uploadfile2);
$percent1 = $width / $maxx;
$percent2 = $height / $maxy;
$percent = max($percent1,$percent2);
$new_eight = round($height /$percent);
$new_width = round($width /$percent);
$dest_image = imagecreatetruecolor($new_width, $new_eight);
imagecopyresampled ($dest_image, $source_image, 0, 0, 0, 0, $new_width, $new_eight, $width, $height);
header("Content-type: image/jpeg");
ob_start();
imagejpeg($dest_image,$upload2_b);
}
}
else{
copy($_FILES['allegato2']['tmp_name'],$uploadfile2);
$dimensione = getimagesize($uploadfile2);
$h=$dimensione[1];
$w=$dimensione[0];
if($h > $maxx || $w > $maxy){
$source_image = imagecreatefromjpeg($uploadfile2);
list($width, $height) = getimagesize($uploadfile2);
$percent1 = $width / $maxx;
$percent2 = $height / $maxy;
$percent = max($percent1,$percent2);
$new_eight = round($height /$percent);
$new_width = round($width /$percent);
$dest_image = imagecreatetruecolor($new_width, $new_eight);
imagecopyresampled ($dest_image, $source_image, 0, 0, 0, 0, $new_width, $new_eight, $width, $height);
header("Content-type: image/jpeg");
ob_start();
imagejpeg($dest_image,$uploaddir2 . $uploadfile2);
}
}
}
if (is_uploaded_file($_FILES['allegato3']['tmp_name'])){
if(file_exists($upload3_b)){
while(file_exists($upload3_b)){
$upload3_b = substr($upload3_b,0,strpos($upload3_b,"."))."_$t". strstr($upload3_b,".");
$t++;
}
list ($immag,$macchine,$uploadfile3_rn) = split ("/",$upload3_b,3);
copy($uploadfile3, $uploaddir2.$uploadfile3_rn);
$uploadfile3 = $upload3_b;
$dimensione = getimagesize($uploadfile3);
$h=$dimensione[1];
$w=$dimensione[0];
if($h > $maxx || $w > $maxy){
$source_image = imagecreatefromjpeg($uploadfile3);
list($width, $height) = getimagesize($uploadfile3);
$percent1 = $width / $maxx;
$percent2 = $height / $maxy;
$percent = max($percent1,$percent2);
$new_eight = round($height /$percent);
$new_width = round($width /$percent);
$dest_image = imagecreatetruecolor($new_width, $new_eight);
imagecopyresampled ($dest_image, $source_image, 0, 0, 0, 0, $new_width, $new_eight, $width, $height);
header("Content-type: image/jpeg");
ob_start();
imagejpeg($dest_image,$upload3_b);
}
}
else{
copy($_FILES['allegato3']['tmp_name'],$uploadfile3);
$dimensione = getimagesize($uploadfile3);
$h=$dimensione[1];
$w=$dimensione[0];
if($h > $maxx || $w > $maxy){
$source_image = imagecreatefromjpeg($uploadfile3);
list($width, $height) = getimagesize($uploadfile3);
$percent1 = $width / $maxx;
$percent2 = $height / $maxy;
$percent = max($percent1,$percent2);
$new_eight = round($height /$percent);
$new_width = round($width /$percent);
$dest_image = imagecreatetruecolor($new_width, $new_eight);
imagecopyresampled ($dest_image, $source_image, 0, 0, 0, 0, $new_width, $new_eight, $width, $height);
header("Content-type: image/jpeg");
ob_start();
imagejpeg($dest_image,$uploaddir2 . $uploadfile3);
}
}
}
if(is_uploaded_file($_FILES['allegato1']['tmp_name'])){
unlink($del_1);
}
if(is_uploaded_file($_FILES['allegato2']['tmp_name'])){
unlink($del_2);
}
if(is_uploaded_file($_FILES['allegato3']['tmp_name'])){
unlink($del_3);
}
?>
per quello che capisco di php penserei che dovrei mettere una condizione che vada a verificare quale allegato (foto) è stato caricato. Vorrei evitare di fare tre pagine per le tre foto da caricare. Qualquno mi aiuta?