Ciao a tutti,
sto creando un file upload muliplo, cioé selezioni il numero di file che vuoi mettere e mi stampa la selezione del file, ora se ne carico uno sul server funziona ma se provo a mettere per esempio 2 file non va, sapete dirmi dove sbaglio gentilmente?
Codice PHP:
<?php
// Recupero il numero per stampare diversi file browse
$numberfile = $_POST['uploadfile'];
// Numero massimo per il menu a tendina
$maxFileUpload = "30";
// Grandezza massima dei file da caricare
$MAX_FILE_SIZE = "20000";
// Tipo di estenzioni consentite
$allowed_types = array("image/gif","image/pjpeg","image/jpeg");
// Destinazione file da caricare sul server
$target_path = "./upload/";
$target_path = $target_path . basename($fileupload_name);
/////////////////////////////////////////////////////////////////////////
$fileupload_temp = $_FILES['fileupload']['tmp_name'];
$fileupload_name = $_FILES['fileupload']['name'];
$fileupload_size = $_FILES['fileupload']['size'];
$fileupload_type = $_FILES['fileupload']['type'];
$fileupload_error = $_FILES['fileupload']['error'];
// Controllo se Submit é impostato
if (isset($_POST['Submit'])) {
// Controllo se il file é selezionato
if (empty($fileupload_name)) {
$msg = "<span class=\"TestoLinks\">Selezionare il file!</span>";
}
// Controllo l'estenzione del file
elseif (!in_array($fileupload_type, $allowed_types)) {
$msg = "<span class=\"TestoLinks\">Sono ammessi solo file \"jpg\".</span>";
}
// Controllo la dimensione del file
elseif ($fileupload_size > $MAX_FILE_SIZE) {
$msg = "<span class=\"TestoLinks\">Il file $fileupload_name é troppo grande.</span>";
}
// Controllo se il file esiste
elseif (file_exists($target_path)) {
$msg = "<span class=\"TestoLinks\">Il file $fileupload_name esiste già. Rinomina il file.</span>";
$img = "<img src=\"./upload/$fileupload_name\" width=\"120\" height=\"80\">";
}
// Se il file é corretto allora copialo sul server
else {
move_uploaded_file($fileupload_temp, $target_path);
$msg = "<span class=\"TestoLinks\">Il file $fileupload_name é stato caricato con successo.</span>";
$img = "<img src=\"./upload/$fileupload_name\" width=\"120\" height=\"80\">";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
Seleziona il numero di file che vuoi caricare </p>
<form id="selectNumber" name="selectNumber" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<select name="uploadfile" id="uploadfile">
<?php
for($i=1;$i<=$maxFileUpload;$i++) {
echo "<option value=\"$i\">$i</option>";
}
?>
</select>
<input name="go" type="submit" id="go" value="Go" />
</form>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data" name="fileupload" id="fileupload">
<input type="hidden" name="MAX_FILE_SIZE" value="$MAX_FILE_SIZE"/>
<?php
for($i=1;$i<=$numberfile;$i++) {
echo "<input type=\"file\" name=\"fileupload\" id=\"fileupload\" />
";
}
?>
<input name="Submit" type="submit" id="Submit" value="Submit" />
</form>
<?php echo $msg."
".$img;?></p>
</body>
</html>
Grazie Michel