ciao a tutti
ho modificato il codice per ridimensionare la foto, ma mi da un errore di permess sulla cartella
Warning: imagejpeg() [function.imagejpeg]: Unable to open '../pro_images/thumb/' for writing: Permission denied in C:\Program Files\EasyPHP 2.0b1
adesso ho provato sia su win xp e vista, ma non va.i permessi della cartella sono ok, vi chiedo; ho sbaliato io qualcosa nel codice? o è il server locale?
ps io salvo il collegamento della foto nel database "="../pro_images/foto/", pero cosi la foto la vedo solo nelle pagine che sono in una sottocartella della root mentre pro_images/foto/ e nella root. come devo fare per visualizzare la foto salvata con il collegamento ../pro_images/foto/ in tutte le pagine?
grazie a tutti
Codice PHP:
if ((isset($_POST["immagine"])) and ($_POST["immagine"] == "") )
$type = $_FILES['immagine']['type'];
$type = array("image/gif","image/x-png", "image/png","image/pjpeg","image/jpeg", "image/jpg");
if(!in_array($_FILES['immagine']['type'],$type))
{
die("Il file non è di un tipo consentito, sono ammessi solo i seguenti: " . implode("," , $type) . ".");
}
$dir ="../pro_images/foto/";
$destination_path = "../pro_images/thumb/";
$timestamp = time();
if (!file_exists($destination_path))
{
mkdir($destination_path , 0777);
}
if (!file_exists($dir))
{
mkdir($dir , 0777);
}
$urlimmagine = $dir.time() .'-'. $_FILES['immagine']['name'];
copy($_FILES['immagine']['tmp_name'], $urlimmagine);
$sImgInfo = getimagesize($urlimmagine);
$max_width = "1800";
$max_height = "1800";
$sMaxWidth = $sImgInfo[0];
$sMaxHeight = $sImgInfo[1];
if ($sMaxWidth > $max_width || $sMaxHeight > $max_height) {
die ("Errore di Dimisioni" .mysql_error());
exit; }
list($width, $height, $type, $attr) = @getimagesize( $urlimmagine);
switch($sImgInfo[2])
{
case 1: $sType = IMG_GIF; break;
case 2: $sType = IMG_JPG; break;
case 3: $sType = IMG_PNG; break;
case 4: $sType = IMG_WBMP; break;
default: return $urlimmagine; break;
}
switch($sType)
{
case IMG_GIF:
if (!function_exists('imagecreatefromgif')) return $urlimmagine;
$srcImage = imagecreatefromgif($urlimmagine);
break;
case IMG_JPG:
if (!function_exists('imagecreatefromjpeg')) return $urlimmagine;
$srcImage = imagecreatefromjpeg($urlimmagine);
break;
case IMG_PNG:
if (!function_exists('imagecreatefrompng')) return $urlimmagine;
$srcImage = imagecreatefrompng($urlimmagine);
break;
case IMG_WBMP:
if (!function_exists('imagecreatefromwbmp')) return $urlimmagine;
$srcImage = imagecreatefromwbmp($urlimmagine);
break;
default: return $urlimmagine;
}
if($srcImage)
{
/* Recupera la dimensione in pixel dell'immagine d'origine */
$srcWidth = $sImgInfo[0];
$srcHeight = $sImgInfo[1];
/*
* E imposta a zero quelle di destinazione o alla dimensione della
* sorgente se non è limitata
*/
$sNewWidth = ($sMaxWidth == 250 ? $srcWidth : 0);
$sNewHeight = ($sMaxHeight == 250 ? $srcHeight : 0);
/* Calcola il rapporto di proporzione */
$sPropW = $sNewWidth / $srcWidth;
$sPropH = $sNewHeight / $srcHeight;
if ($sPropW < 1 && $sPropW <= $sPropH)
{
$sNewWidth = $sMaxWidth;
}
if ($sPropH < 1 && $sPropH <= $sPropW)
{
/*
* Vi è limite all'altezza massima, l'immagine d'origine eccede
* tale limite e quest'ultima è anche la dimensione più grande (o
* eguale) tra larghezza ed altezza.
*/
$sNewHeight = $sMaxHeight;
}
/*
* A questo punto, se una delle due nuove dimensioni è ancora pari a
* zero, significa che quest'ultima deve essere ricalcolata in base
* alla sua antagonista per poter rispettare le proporzioni.
*/
if ($sNewWidth > 250 && $sNewHeight == 0)
{
/* Ricalcola l'altezza */
$sRatioWidth = $srcWidth / $sNewWidth;
$sNewHeight = $srcHeight / $sRatioWidth;
}
if ($sNewHeight > 250 && $sNewWidth == 0)
{
/* Ricalcola la larghezza */
$sRatioHeight = $srcHeight / $sNewHeight;
$sNewWidth = $srcWidth / $sRatioHeight;
}
if ($sNewWidth == 250 && $sNewHeight == 0)
{
$sNewWidth = $srcWidth;
$sNewHeight = $srcHeight;
}
/* Procede quindi alla creazione effettiva della thumbnail */
if (!function_exists("imagecreatetruecolor"))
$sDestImage = imagecreate($sNewWidth, $sNewHeight);
else
$sDestImage = imagecreatetruecolor($sNewWidth, $sNewHeight);
imagecopyresized($sDestImage, $srcImage, 0, 0, 0, 0, $sNewWidth, $sNewHeight, $srcWidth, $srcHeight);
switch($sType)
{
case IMG_GIF: imagegif($sDestImage, $destination_path); break;
case IMG_JPG: imagejpeg($sDestImage, $destination_path); break;
case IMG_PNG: imagepng($sDestImage, $destination_path); break;
case IMG_WBMP: imagewbmp($sDestImage, $destination_path); break;
}
/* Libera la memoria */
imagedestroy($srcImage);
imagedestroy($sDestImage);
return $destination_path;
}
else
{
return $urlimmagine;
}
copy($_FILES['immagine']['tmp_name'], $destination_path.$sDestImage);