prendo per buono senza gurdare il codice prima di
Codice PHP:
if((fExt($uploadfile) == 'gif') or (fExt($uploadfile) == 'jpg') or (fExt($uploadfile) == 'jpeg') or (fExt($uploadfile) == 'png')) {
modificherei il file così:
Codice PHP:
//Funzione Replace " " in "_"
function fSpace($string)
{
return str_replace(" ", "_", $string);
}
//Funzione per ricavare l' estensione di un File
function fExt($string)
{
//Controllo il file
$trova_punto = explode(".", $string);
$estensione = $trova_punto[count($trova_punto) - 1];
$estensione = strtolower($estensione);
// Se non ci sono estensioni
if (isset($trova_punto[1]) == FALSE)
{
return '';
}
//Ritorno il valore dell' estensione
return $estensione;
}
//Fine funzioni
//Effettuo l' upload dell' immagine...
$uploaddir = 'upload_img/';
$uploadfile = fspace($_FILES['txt_file']['name']);
$upload = $uploaddir . $uploadfile;
//Controllo che sia stato specificato un file
if(!strlen($uploadfile) == 0)
{
//Controllo l' estensione del file
if((fExt($uploadfile) == 'gif') or (fExt($uploadfile) == 'jpg') or (fExt($uploadfile) == 'jpeg') or (fExt($uploadfile) == 'png'))
{
$max_width=300;
if (!extension_loaded('gd') && !extension_loaded('gd2')){
trigger_error("GD is not loaded", E_USER_WARNING);
return false;
}
list($width_orig, $height_orig, $image_type) = getimagesize($uploadfile);
switch ($image_type){
case 1:
$im = imagecreatefromgif($uploadfile);
break;
case 2:
$im = imagecreatefromjpeg($uploadfile);
break;
case 3:
$im = imagecreatefrompng($uploadfile);
break;
default:
trigger_error('Immagine non valida!', E_USER_WARNING);
break;
}
$aspect_ratio = (float) $height_orig / $width_orig;
$thumb_height = round($thumb_width * $aspect_ratio);
while($thumb_height>$max_width){
$thumb_width -= 10;
$thumb_height = round($thumb_width * $aspect_ratio);
}
$newImg = imagecreatetruecolor($thumb_width, $thumb_height);
/* Check if this image is PNG or GIF, then set if Transparent*/
if(($image_type == 1) OR ($image_type==3)){
imagealphablending($newImg, false);
imagesavealpha($newImg,true);
$transparent = imagecolorallocatealpha($newImg, 255, 255, 255, 127);
imagefilledrectangle($newImg, 0, 0, $thumb_width, $thumb_height, $transparent);
}
imagecopyresampled($newImg, $im, 0, 0, 0, 0, $thumb_width, $thumb_height, $width_orig, $height_orig);
switch ($image_type)
{
case 1:
imagegif($newImg, $upload);
break;
case 2:
imagejpeg($newImg, $upload);
break;
case 3:
imagepng($newImg, $upload);
break;
default:
trigger_error('Ridimensionamento fallito!', E_USER_WARNING);
break;
}
}
}else{
//Messaggio di errore
echo "Specificare un file !";
echo "
[url='form.php']Torna dietro[/url]";
}