Codice PHP:
ini_set("memory_limit", "50M");
$dir = base64_decode($_GET['dir']);
$thumb;
$tmp = $_FILES['file1']['tmp_name'];
echo $FILES['file1']['size'];
if ($_FILES['file1']['size'] > 3145728) { // la bellezza di 3 mb
echo '<p class = "centro">Il file eccede la dimensione massima di 3 MB[/b]
[/b]
[/b]
</p>';
}
elseif ($_FILES['file1']['size'] == 0) {
echo '<p class = "centro">Nessun file sembra apparentemente caricato, controlla che il suo nome non contenga spazi o caratteri di sottolineatura (_)[/b]
[/b]
[/b]
</p>';
}
/* Da qua iniziano le procedure di salvataggio e elaborazione dell'immagine */
if (file_exists("immagini/". $dir ."/" . $_FILES['file1']['name'])) { // Es.: immagini/fotoGruppi/img1.png
echo '<p class = "centro">Esiste giá un file con questo nome
</p>';
exit(1);
}
if (!move_uploaded_file($tmp, "immagini/" . $dir . "/" . $_FILES['file1']['name'])) {
echo '<p class = "centro">Errore interno: impossibile caricare il file
</p>';
}
else {
$tmp = "immagini/". $dir ."/" . $_FILES['file1']['name'];
list($lar, $lun) = getimagesize($tmp);
switch ($_FILES['file1']['type']) {
// Controllo il tipo dell'immagine...
case "image/x-windows-bmp":
case "image/bmp":
$thumb = imagecreatefromwbmp($tmp);
$thumb_2 = imagecreatetruecolor(120, 90); // La vera thumbnail
imagecopyresampled($thumb_2, $thumb, 0, 0, 0, 0, 120, 90, $lar, $lun);
imagewbmp($thumb_2,"immagini/" . $dir . "/thumbs/_php_thumb_" . $_FILES['file1']['name']);
break;
case "image/jpeg":
case "image/pjpeg":
$thumb = imagecreatefromjpeg($tmp);
$thumb_2 = imagecreatetruecolor(120, 90);
imagecopyresampled($thumb_2, $thumb, 0, 0, 0, 0, 120, 90, $lar, $lun);
imagejpeg($thumb_2,"immagini/" . $dir . "/thumbs/_php_thumb_" . $_FILES['file1']['name']);
break;
case "image/png":
case "image/x-png":
$thumb = imagecreatefrompng($tmp);
$thumb_2 = imagecreatetruecolor(120, 90);
imagecopyresampled($thumb_2, $thumb, 0, 0, 0, 0, 120, 90, $lar, $lun);
imagepng($thumb_2,"immagini/" . $dir . "/thumbs/_php_thumb_" . $_FILES['file1']['name']);
break;
case "image/gif":
$thumb = imagecreatefromgif($tmp);
$thumb_2 = imagecreatetruecolor(120, 90);
imagecopyresampled($thumb_2, $thumb, 0, 0, 0, 0, 120, 90, $lar, $lun);
imagegif($thumb_2,"immagini/" . $dir . "/thumbs/_php_thumb_" . $_FILES['file1']['name']);
break;
default:
echo '<p class = "centro">Il formato del file non è consentito, formati consentiti: *.bmp, *.jpeg, *.jpg, *.png, *.gif
';
exit(1); // Lascio morire l'applicazione in caso di errore
}
echo '<p class = "centro">L\'immagine è stata aggiunta correttamente
</p>';
imagedestroy($thumb); // Libero preziosissimo spazio nella memoria...
imagedestroy($thumb_2);
}
Ora è però sorto un'altro problema... e ti pareva!