[PHP] upload con errore

luigi777

Utente Attivo
14 Feb 2008
1.086
1
38
43
Massa, Italy
Salve, ho questo codice che non so come mai non funziona .. ecco il codice:
PHP:
<?php
if (isset($_POST['submit'])) {
    $j = 0; //Variable for indexing uploaded image
    
    $target_path = "uploads/";  //Declaring Path for uploaded images
    for ($i = 0; $i < count($_FILES['file']['name']); $i++) { //loop to get individual element from the array
        if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) { //if file moved to uploads folder
                echo $j. ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>';
            } else { //if file was not moved.
                echo $j. ').<span id="error">please try again!.</span><br/><br/>';
            }       
    }
}

mi segnala:
Warning: move_uploaded_file(): The second argument to copy() function cannot be a directory in D:\www\test\upload.php on line 7

Warning: move_uploaded_file(): Unable to move 'D:\xampp\tmp\phpA41E.tmp' to 'uploads/' in D:\www\test\upload.php on line 7
0).please try again!.


Warning: move_uploaded_file(): The second argument to copy() function cannot be a directory in D:\www\test\upload.php on line 7

Warning: move_uploaded_file(): Unable to move 'D:\xampp\tmp\phpA43F.tmp' to 'uploads/' in D:\www\test\upload.php on line 7
0).please try again!.

ora ci sono più move_uploaded_file perché e un upload multiplo .. pero non so perché dice cosi.

Aspetto qualcuno che mi dia una mano.. in tanto ringrazio in anticipo.

Buona giornata.
 
ciao
move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path))
la variabile $target_path non può essero solo il nome della cartella in cui vuoi caricare il file, ma deve contenere anche il nome del file che vuoi caricare
es
PHP:
<?php
//....
 $target_path = "uploads/";  //Declaring Path for uploaded images
    for ($i = 0; $i < count($_FILES['file']['name']); $i++) { //loop to get individual element from the array
        if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path.$_FILES['file']['name'][$i])) { //if file moved to uploads folder
                echo $j. ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>';
            } else { //if file was not moved.
                echo $j. ').<span id="error">please try again!.</span><br/><br/>';
            }       
    }
//...
?>
cioè deve uplodare il file temporaneo xy.tmp nella cartella up con nome wz.jpg
 

Discussioni simili