简体   繁体   中英

Uploading multiple files uploads only one

This function uploads only 1 file instead of 6. The reason is that it returns array $fileDirectories with dimension 1 instead of 6 and I can't understand why. count($_FILES['file']['name']) echoes 6.

function uploadFile( $link){

        $fileDirectories = array();
        echo 'count files: '.count($_FILES['file']['name']).'<br>';
        for($i=0; $i<count($_FILES['file']['name']); $i++){


                        move_uploaded_file($_FILES["file"]["tmp_name"][$i],
                                            "../upload/" . $_FILES["file"]["name"][$i]);
                        $fileDirectory = "upload/" . $_FILES["file"]["name"][$i];
                        array_push($fileDirectories, $fileDirectory);
                        return $fileDirectories;


        }
echo 'array count:'.count($fileDirectories).'<br>';
//echoes 1 when it suppose to be 6 file directories.
//it also uploads to ftp server only 1 of them

Move return $fileDirectories; statement outside the for loop.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM