innanzitutto grazie per la disponibilità!
io praticamente per uploadare le immagini sul server e inserirne il percorso su db, e per il ridimensionamento utilizzo il seguente codice....
Codice PHP:
if(isset($_FILES['foto']))
$foto = $_FILES['foto'];
else
$foto = "";
$numero = count($foto['name']);
$datafoto = date('YmdHis');
for($i=1; $i<$numero; $i++){
if (is_uploaded_file($foto['tmp_name'][$i])){
// Controllo che il file non superi i 1 MB
if ($foto['size'][$i] > 1024000) {
echo "<script language='javascript'>alert('".$descri[33]."!! ".$descri[34]."'); history.back();</script>";
break;
}
// Ottengo le informazioni sull'immagine
list($width, $height, $type, $attr) = getimagesize($foto['tmp_name'][$i]);
// Controllo che il file sia in uno dei formati GIF, JPG o PNG
if (($type!=1) && ($type!=2) && ($type!=3)) {
echo "<script language='javascript'>alert('".$descri[35]."!!\n".$descri[34]."'); history.back();</script>";
break;
}
// Sposto il file nella cartella da me desiderata
$nomefile = $datafoto.$foto['name'][$i];
if (!move_uploaded_file($foto['tmp_name'][$i], 'foto/big/'.$nomefile)) {
echo "<script language='javascript'>alert('".$descri[36]."!!\n".$descri[34]."'); history.back();</script>";
break;
}
else {
// Ottengo le informazioni sull'immagine originale
list($width, $height, $type, $attr) = getimagesize('foto/big/'.$datafoto.$foto['name'][$i]);
//chiamo la funzione calcola_miniatura
list($h_thumb,$w_thumb) = calcola_miniatura($width, $height);
// Creo la versione 120*90 dell'immagine (thumbnail) ???
$thumb = imagecreatetruecolor($h_thumb, $w_thumb);
if($type == 1) #gif
$source = imagecreatefromgif('foto/big/'.$datafoto.$foto['name'][$i]);
elseif($type == 2) #jpg
$source = imagecreatefromjpeg('foto/big/'.$datafoto.$foto['name'][$i]);
else #png
$source = imagecreatefrompng('foto/big/'.$datafoto.$foto['name'][$i]);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $h_thumb, $w_thumb, $width, $height);
// Salvo l'immagine ridimensionata
if($type == 1)
imagegif($thumb, "foto/thumb/".$datafoto.$foto['name'][$i], 75);
elseif($type == 2)
imagejpeg($thumb, "foto/thumb/".$datafoto.$foto['name'][$i], 75);
else
imagepng($thumb, "foto/thumb/".$datafoto.$foto['name'][$i], 75);
$sql = "insert into foto(idannuncio, nomefoto) values ('$idcontrollo', '".$datafoto.$foto['name'][$i]."')";
$result = mysql_query($sql) or die("errore query foto ".mysql_error());
}
}
}
la funzione per calcolare la miniatura è questa...
Codice PHP:
$dim_thumb = 120;
function calcola_miniatura_big($w, $h) {
global $dim_thumb;
$ret = array(0,0);
$wt = 0;
$wh = 0;
if ($w > $h) {
$wt = $dim_thumb;
$ht = $dim_thumb * $h / $w;
}
else {
$ht = $dim_thumb;
$wt = $dim_thumb * $w / $h;
}
$ret[0] = $wt;
$ret[1] = $ht;
return $ret;
}
ora vorrei integrare la funzione trovato su html.it sul mio procedimento e non so proprio come procedere e dove farla partire
ho fatto delle prove ma niente da fare