Ciao a tutti
Ho creato una funzione per l'upload e il resize dei file jpg utilizzabile ovunque all'interno del sito
function resize($file, $dir, $larg, $alt) {
//controllo se il file immagine esiste
if (isset($_FILES['file']['name']) && ($_FILES['file']['name'] !="") ) {
//controllo se il file immagine è jpeg
if (($_FILES['file']['type'] == "image/jpeg") ||($_FILES['file']['type'] == "image/pjpeg")) {
// controllo se ha un nome
$a = time();
$nomefile = $a.($_FILES['file']['name']);
$DirMin = $_SERVER['DOCUMENT_ROOT']."/yyy/".$dir."\\"; //
$new_name = $a.".jpg";
$tmpImage = $_FILES['file']['tmp_name'];
$src = imagecreatefromjpeg($tmpImage);
list($width,$height) = getimagesize($tmpImage);
$x_ratio = $larg / $width;
$y_ratio = $alt / $height;
if( ($width <= $larg) && ($height <= $alt) ){
$tn_width = $width;
$tn_height = $height;
}else if(($x_ratio * $height) < $alt){
$tn_height = ceil($x_ratio * $height);
$tn_width = $larg;
}else{
$tn_width = ceil($y_ratio * $width);
$tn_height = $alt;
}
$tmp=imagecreatetruecolor($tn_width,$tn_height);
imagecopyresampled($tmp,$src,0,0,0,0,$tn_width, $tn_height,$width,$height);
$filename = $DirMin.$nomefile;
imagejpeg($tmp,$filename,100);
imagedestroy($src);
imagedestroy($tmp);
} else { echo "[b]Possono essere inseriti solo files di tipo jpg o jpeg. Attendi.....[b]"; exit(header("Refresh: 10; url=modifica.php")); }//fine controllo nome
} else { $nomefile = "0"; } //fine controllo type
} ?>
mi fa l'upload e il resize ma non mi ritorna $nomefile per l'inserimento nel db