TorpedoBlu
04-01-2007, 21:41
uso queste funzioni per creare l'immagine e la sua miniatura per i preview
<?
error_reporting(2047);
/*--------------------------------------------------*/
/*FUNZIONI PER IL CARICAMENTO DI IMMAGINI SUL SERVER*/
/*--------------------------------------------------*/
/*absolutepath è la cartella dove caricare il file (esempio ./img), $file è lavariabile proveniente dalla form e $filename il nome del file sul server*/
function caricaImmagine($absolute_path, $file, $nome_file){
$dir = "dir";
$file_name=$nome_file.".jpg";
if ($file != "")
{
if (file_exists("$absolute_path/$file_name"))
{
die("errore2: Un file con lo stesso nome è già online, RINOMINARLO e inviarlo nuovamente");
}
copy($file, "".$absolute_path."/".$file_name.""); /*or die("errore4: Problemi sul server... riprova più tardi o scrivici una email");
return 1;*/
}
else
{
//die("errore5: Non hai selezionanto nessun file!!!");
return 0;
}
}
/*stesse caratteristiche di caricaImmagine, ma la variabile dimensione definisce il massimo consentito in X e Y*/
function caricaImmagineModificata($absolute_path, $file, $nome_file, $dimensione){
$dir = "dir";
$file_name=$nome_file.".jpg";
if ($file != "")
{
if (file_exists("$absolute_path/$file_name"))
{
die("errore2: Un file con lo stesso nome è già online, RINOMINARLO e inviarlo nuovamente");
}
//crea la miniatura
$wsize = $dimensione; //larghezza massima e...
$hsize = $dimensione;; //altezza massima della thumbnail
$im_size = GetImageSize($file);
$imageWidth = $im_size[0];
$imageHeight = $im_size[1];
$thumb_width = $wsize;
$thumb_height = $hsize;
$im2 = imagecreatefromjpeg($file);
if ($imageWidth>=$imageHeight)
{
$width = $thumb_width;
$height = ($width/$imageWidth)*$imageHeight;
}
else
{
$height = $thumb_height;
$width = ($height/$imageHeight)*$imageWidth;
}
$im = imageCreateTrueColor($width, $height);
if (function_exists('ImageCopyResampled')) {
ImageCopyResampled($im,$im2, 0, 0, 0, 0, $width, $height, $imageWidth, $imageHeight);
} else {
ImageCopyResized($im,$im2, 0, 0, 0, 0, $width, $height, $imageWidth, $imageHeight);
}
$nome_file_output=$absolute_path."/".$nome_file.".jpg";
/* Header("Content-type: image/jpg"); */
Imagejpeg($im, $nome_file_output, 85); //85 è la qualità (da 1 a 100)
ImageDestroy($im);
ImageDestroy($im2);
return 1;
}
else
{
//die("errore5: Non hai selezionanto nessun file!!!");
return 0;
}
}
?>
ma dopo il trasferimento di dominio mi da questo errore:
Fatal error: Allowed memory size of 12582912 bytes exhausted (tried to
allocate 8192 bytes)
in /web/htdocs/www.athenaband.com/home/immagini.php on line 54
come mai?
<?
error_reporting(2047);
/*--------------------------------------------------*/
/*FUNZIONI PER IL CARICAMENTO DI IMMAGINI SUL SERVER*/
/*--------------------------------------------------*/
/*absolutepath è la cartella dove caricare il file (esempio ./img), $file è lavariabile proveniente dalla form e $filename il nome del file sul server*/
function caricaImmagine($absolute_path, $file, $nome_file){
$dir = "dir";
$file_name=$nome_file.".jpg";
if ($file != "")
{
if (file_exists("$absolute_path/$file_name"))
{
die("errore2: Un file con lo stesso nome è già online, RINOMINARLO e inviarlo nuovamente");
}
copy($file, "".$absolute_path."/".$file_name.""); /*or die("errore4: Problemi sul server... riprova più tardi o scrivici una email");
return 1;*/
}
else
{
//die("errore5: Non hai selezionanto nessun file!!!");
return 0;
}
}
/*stesse caratteristiche di caricaImmagine, ma la variabile dimensione definisce il massimo consentito in X e Y*/
function caricaImmagineModificata($absolute_path, $file, $nome_file, $dimensione){
$dir = "dir";
$file_name=$nome_file.".jpg";
if ($file != "")
{
if (file_exists("$absolute_path/$file_name"))
{
die("errore2: Un file con lo stesso nome è già online, RINOMINARLO e inviarlo nuovamente");
}
//crea la miniatura
$wsize = $dimensione; //larghezza massima e...
$hsize = $dimensione;; //altezza massima della thumbnail
$im_size = GetImageSize($file);
$imageWidth = $im_size[0];
$imageHeight = $im_size[1];
$thumb_width = $wsize;
$thumb_height = $hsize;
$im2 = imagecreatefromjpeg($file);
if ($imageWidth>=$imageHeight)
{
$width = $thumb_width;
$height = ($width/$imageWidth)*$imageHeight;
}
else
{
$height = $thumb_height;
$width = ($height/$imageHeight)*$imageWidth;
}
$im = imageCreateTrueColor($width, $height);
if (function_exists('ImageCopyResampled')) {
ImageCopyResampled($im,$im2, 0, 0, 0, 0, $width, $height, $imageWidth, $imageHeight);
} else {
ImageCopyResized($im,$im2, 0, 0, 0, 0, $width, $height, $imageWidth, $imageHeight);
}
$nome_file_output=$absolute_path."/".$nome_file.".jpg";
/* Header("Content-type: image/jpg"); */
Imagejpeg($im, $nome_file_output, 85); //85 è la qualità (da 1 a 100)
ImageDestroy($im);
ImageDestroy($im2);
return 1;
}
else
{
//die("errore5: Non hai selezionanto nessun file!!!");
return 0;
}
}
?>
ma dopo il trasferimento di dominio mi da questo errore:
Fatal error: Allowed memory size of 12582912 bytes exhausted (tried to
allocate 8192 bytes)
in /web/htdocs/www.athenaband.com/home/immagini.php on line 54
come mai?