salve a tutti.
Premetto che non sono fortissimo con il php.
allora:
Ho questo codice che serve per fare l'upload di un img e creare una thumb:
Codice PHP:
do {
if (is_uploaded_file($_FILES['image']['tmp_name'])) {
// Controllo che il file non superi i 18 KB
if ($_FILES['image']['size'] > 18333432) {
$msg = "
Il file non deve superare i 18 KB!!</p>";
break;
}
// Ottengo le informazioni sull'immagine
list($width, $height, $type, $attr) = getimagesize($_FILES['image']['tmp_name']);
// Controllo che le dimensioni (in pixel) non superino 160x180
if (($width > 600) || ($height > 600)) {
$msg = "
Dimensioni non corrette!!</p>";
break;
}
// Controllo che il file sia in uno dei formati GIF, JPG o PNG
if (($type!=1) && ($type!=2) && ($type!=3)) {
$msg = "
Formato non corretto!!</p>";
break;
}
// Verifico che sul sul server non esista già un file con lo stesso nome
// In alternativa potrei dare io un nome che sia funzione della data e dell'ora
if (file_exists('upload_img/'.$_FILES['image']['name'])) {
$msg = "
File già esistente sul server. Rinominarlo e riprovare.</p>";
break;
}
// Sposto il file nella cartella da me desiderata
if (!move_uploaded_file($_FILES['image']['tmp_name'], 'upload_img/'.$_FILES['image']['name'])) {
$msg = "
Errore nel caricamento dell'immagine!!</p>";
break;
}
}
$foto=$_FILES['image']['name'];
} while (false);
echo $msg;
// Ottengo le informazioni sull'immagine originale
list($width, $height, $type, $attr) = getimagesize($_FILES['image']['name']);
// Creo la versione 90*90 dell'immagine (thumbnail)
$thumb = imagecreatetruecolor(90, 90);
$source = imagecreatefromjpeg($_FILES['image']['name']);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, 120, 90, $width, $height);
// Salvo l'immagine ridimensionata
imagejpeg($thumb, "upload_img/thumb/".$_FILES['image']['name'], 75);
?>
L'upload lo esegue correttamente ma al momento della creazione della thub mi da questo errore:
Warning: getimagesize(nomefile.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /web/htdocs/www.rarostardust.it/home/undergroundattack/admin/load_rece.php on line 43
Warning: imagecreatefromjpeg(nomefile.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in /web/htdocs/www.xxx.it/home
Warning: imagecopyresampled(): supplied argument is not a valid Image resource
stranamente la thumb viene creata e salvata con le dimensioni impostate ma compare competamente nera.
Mi potete aiutare??