Ciao a tutti,
ho un problema con questa funzione che carica in una cartella temporanea un immagine passata tramite un form e che successivamente la ridimensiona mantenendo le proporzioni.
La funzione si comporta correttamente fino a quando memorizza nella directory temporanea l'immagine, poi non succede nulla e soprattutto non mi da un errore.... ecco il codice:
<?php
function upload_image($attach,$file_name,$file_type){
if (is_uploaded_file($attach)) {
if( $file_type == "image/jpeg" || $file_type == "image/gif" || $file_type == "image/jpg"){
if (file_exists('upload_image_temp/'.$file_name)) {
return false;
}
if (!move_uploaded_file($attach, 'upload_image_temp/'.$file_name)) {
return false;
}
if( $file_type == "image/jpeg" || $file_type == "image/jpg"){
$path_to_img="upload_image_temp/".$file_name;
//$imagehw = getimagesize("upload_image_temp/".$file_name);
list($width, $height) = getimagesize($path_to_img);
$final_width=150;
$final_height=(150*$width)/$height;
$dst_img=@imagecreatetruecolor(final_width,$final_ height);
$src_img=@imagecreatefromjpeg("$path_to_img");
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $final_width, $final_height, $width, $height);
imagejpeg($dst_img,"upload_image".$file_name,90);
unlink ("upload_image_temp/"."$file_name");
return true;
}
if( $file_type == "image/png"){
$path_to_img="upload_image_temp/".$file_name;
$imagehw = getimagesize($path_to_img);
$final_width=150;
$final_height=(150*$imagehw[1])/$imagehw[0];
$dst_img=@imagecreatetruecolor(final_width,$final_ height);
$src_img=@imagecreatefrompng($path_to_img);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$fina l_width,$final_height,ImageSX($src_img),ImageSY($s rc_img));
imagepng($dst_img,"upload_image".$file_name,90);
unlink ("upload_image_temp/".$file_name);
return true;
}
return true;
}
else{
return false;
}
}
}
?>
aspetto con ansia una vostra risposta.