Inoltre userei move_uploaded_file o al massimo rename, perché tenere una copia in /tmp? ti è necessaria?
al resto ti hanno risposto emanuele e paoletta. Se vuoi usare \n ed avere un comportamento simile sia a browser sia in output standard usa nl2br() quando vuoi mostrare su browser, ma nel tuo caso non so quanto ti serva, mi sembra tutto a browser
poi naturalmente se metti in produzione cerca di prevenire errori, controlla l'input, etc...
io ho provato il tuo codice, con le correzioni che ti ho detto e con l'aggiunta di qualche riga per debug e mi funziona, anche se non avrei fatto così
comunque questo è quello che ho testato e mi funziona
Codice: Seleziona tutto
<?php
$up_path = "upload";
echo '<html>
<title>Upload file</title>
<body>';
function num_upload() {
echo '<form action="upload.php" method="post">
How many images do you want to upload?
<input type="text" name="num">
<input type="submit" value="Submit">
</form>';
}
function multi_upload($num) {
echo '<form action="upload.php" enctype="multipart/form-data" method="post">
<table border="0" width="400" cellspacing="0" cellpadding="0" align=center>';
for ($i = 1; $i <= $num; $i++) {
echo '<tr><td>'."Image ".$i.": ".'</td>
<td><input type="file" name="image[]"></td></tr>
<tr><td>'."Desc. ".'</td>
<td><input type="text" name="desc[]"></td></tr>';
}
echo '<tr><td colspan=2 align=center>
<input type=submit value="Add Image(s)"></td></tr>
</table></form>';
}
function upload($up_path) {
$j = 1;
while (list($key,$value) = each($_FILES['image']['name'])) {
print "1<br>\n";
//list($desc_k,$desc_v) = each($_REQUEST['desc']['name']);
echo "2<br>\n";
if (! empty($value)) {
echo $value."<br>\n";
$filename = $value;
$filename = str_replace(" ","_",$filename);
$filename = str_replace("'","",$filename);
echo $filename."<br>\n";
$path = $up_path."/".$filename;
if (file_exists($path)) {
echo "The file ".$filename." already exists.\n";
break;
}
echo $path."<br>\n";
$tempfile=$_FILES['image']['tmp_name'][$key];
echo $tempfile."<br>\n";
if (file_exists($tempfile)) {
echo "The file ".$tempfile." exists.\n";
} else {
echo "The file ".$tempfile." not exists.\n";
}
if (copy($tempfile,$path))
echo "File ".$j." caricato<br>\n";
else {
echo "Errore nella copia";
}
if (chmod($path,0660))
echo "File ".$j." chmod'd<br>\n";
if (! empty($desc[$j])) {
$desc_file = fopen("$path/.pics_desc","a");
$imgdesc = $desc_v;
$imgdesc = str_replace("\n"," ",$imgdesc);
$write = $filename.";".$desc_v."\n";
fwrite($desc_file,$write);
fclose();
}
$j++;
}
}
}
num_upload();
if (! empty($_REQUEST['num'])) {
echo'<br /><p>';
multi_upload($_REQUEST['num']);
echo '</p>';
}
if (! empty($_FILES['image'])) {
$up_path = "upload";
echo $_FILES['image']."<br>\n";
echo '<br /><p>';
upload($up_path);
echo '</p>';
}
echo '</body></html>';
il file si chiama upload.php ed è nella directory /home/htdocs/prova ed ho creato una directory /home/htdocs/prova/upload con i permessi per apache
/home/htdocs è la mia docroot