Codice PHP:
<?php
// richiamo lo script responsabile della connessione a MySQL
include "../../connessione.php";
// Firstly Lets build the Category List
$result = mysql_query( "SELECT id_categoria,nome_categoria FROM categorie" );
while( $row = mysql_fetch_array( $result ) )
{
$photo_category_list .= "\n<option value=\"" . $row[0] . "\">" . $row[1] . "</option>";
}
mysql_free_result( $result );
echo "Seleziona categoria: <select name=\"category\">$photo_category_list</select>\n"
?>
<form action="<?php echo $_server['php-self']; ?>" method="post" enctype="multipart/form-data" id="upload">
Immagine 1: <input name="carica_immagine_01" id="carica_immagine_01" size="30" type="file" />
Immagine 2: <input name="carica_immagine_02" id="carica_immagine_02" size="30" type="file" />
<button name="inserisci_immagini" type="submit">Inserisci immagini</button>
</form>
<?php
ini_set("memory_limit","256M");
if(isset($_POST['inserisci_immagini'])){
if(isset($_FILES['carica_immagine_01'])){
$imagename1 = $_FILES['carica_immagine_01']['name'];
$source1 = $_FILES['carica_immagine_01']['tmp_name'];
$target1 = "user_images/".$imagename1;
move_uploaded_file($source1, $target1);
$imagepath = $imagename1;
$save = "user_images/" . $imagepath; //This is the new file you saving
$file = "user_images/" . $imagepath; //This is the original file
list($width, $height) = getimagesize($file) ;
$modwidth = 1024; //large image size
$diff = $width / $modwidth;
$modheight = $height / $diff;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100) ;
$save = "user_images/miniatura-" . $imagepath; //This is the new file you saving
$file = "user_images/" . $imagepath; //This is the original file
list($width, $height) = getimagesize($file) ;
$modwidth = 170; //small thumbnail size
$diff = $width / $modwidth;
$modheight = $height / $diff;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100) ;
$strSQL1 = "INSERT INTO immagini ";
$strSQL1 .="(nome_immagine,categoria_immagine) VALUES ('$imagepath','$category')";
$objQuery = mysql_query($strSQL1);
}
}
if(isset($_POST['inserisci_immagini'])){
if(isset($_FILES['carica_immagine_02'])){
$imagename2 = $_FILES['carica_immagine_02']['name'];
$source2 = $_FILES['carica_immagine_02']['tmp_name'];
$target2 = "user_images/".$imagename3;
move_uploaded_file($source3, $target3);
$imagepath = $imagename2;
$save = "user_images/" . $imagepath; //This is the new file you saving
$file = "user_images/" . $imagepath; //This is the original file
list($width, $height) = getimagesize($file) ;
$modwidth = 1024; //large image size
$diff = $width / $modwidth;
$modheight = $height / $diff;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100) ;
$save = "user_images/miniatura-" . $imagepath; //This is the new file you saving
$file = "user_images/" . $imagepath; //This is the original file
list($width, $height) = getimagesize($file) ;
$modwidth = 170; //small thumbnail size
$diff = $width / $modwidth;
$modheight = $height / $diff;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100) ;
$strSQL2 = "INSERT INTO immagini ";
$strSQL2 .="(nome_immagine,categoria_immagine) VALUES ('$imagepath','$category')";
$objQuery = mysql_query($strSQL2);
}
}
?>
Dov'è che sbaglio?