sto provando a caricare più foto contemporaneamente:
Codice PHP:
// upload_images.php
<form action="check_image.php" method="post" enctype="multipart/form-data">
<table>
<tr>
<td>Upload: </td>
</tr>
<tr>
<td><input type="file" name="uploadfile" /></td>
</tr>
<tr>
<td><input type="file" name="uploadfile2" /></td>
</tr>
<tr>
<td><input type="file" name="uploadfile3" /></td>
</tr>
<tr>
<td>Caption: </td>
<td><input type="text" name="caption" /></td>
</tr>
<tr>
<td>Category: </td>
<td>
<?php
include_once 'config.php';
$query = "select * from category order by title asc";
$result = mysql_query($query) or die(mysql_error($link));
echo '<select name="category">';
echo '<option value="javascript:void(0)">Scegli la categoria</option>';
while ($riga = mysql_fetch_array($result)) {
echo "<option value=" . $riga['title'] . ">" . $riga['title'] . "</option>";
}
echo '</select>';
echo '
';
?>
</td>
</tr>
<tr>
<td><input type="submit" name="upload" value="Upload" /></td>
</tr>
</table>
</form>
Codice PHP:
// check_image.php
$error = 'Formato non supportato';
switch ($type) {
case IMAGETYPE_GIF:
$image = imagecreatefromgif($_FILES['uploadfile']['tmp_name']) or die($error);
$image2 = imagecreatefromgif($_FILES['uploadfile2']['tmp_name']) or die($error);
$image3 = imagecreatefromgif($_FILES['uploadfile3']['tmp_name']) or die($error);
break;
case IMAGETYPE_JPEG:
$image = imagecreatefromjpeg($_FILES['uploadfile']['tmp_name']) or die($error);
$image2 = imagecreatefromjpeg($_FILES['uploadfile2']['tmp_name']) or die($error);
$image3 = imagecreatefromjpeg($_FILES['uploadfile3']['tmp_name']) or die($error);
break;
case IMAGETYPE_PNG:
$image = imagecreatefrompng($_FILES['uploadfile']['tmp_name']) or die($error);
$image2 = imagecreatefrompng($_FILES['uploadfile2']['tmp_name']) or die($error);
$image3 = imagecreatefrompng($_FILES['uploadfile3']['tmp_name']) or die($error);
break;
default:
die($error);
}
// inserisce le info nella tabella
$query = 'insert into images (image_caption,image_date,image_category) values ("' . $image_caption . '","' . $image_date . '","' . $image_category . '")';
$result = mysql_query($query, $db) or die(mysql_error($db));
// recupera il valore image_id generato in fase di inserimento
$last_id = mysql_insert_id();
// assicuriamo che l'immagine non sovrascriva le altre esistenti
$imagename = $last_id . "_" . $_POST['category'] . '.jpg';
$nome = imagejpeg($image, $dir . '/' . $imagename, 100);
$nome2 = imagejpeg($image2, $dir . '/' . $imagename, 100);
$nome3 = imagejpeg($image3, $dir . '/' . $imagename, 100);
imagedestroy($image, $image2, $image3);
in pratica mi carica solo l'ultima foto e mi da un errore su imadestry dicendo che la sintassi è sbagliata.
come faccio a caricare più foto??