上传多个文件只上传一个

时间:2014-03-01 00:09:21

标签: php arrays file upload push

此函数仅上传1个文件而不是6个。原因是它返回的数组$fileDirectories的维度为1而不是6,我无法理解为什么。 count($_FILES['file']['name'])回应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

1 个答案:

答案 0 :(得分:1)

return $fileDirectories;语句移到for循环之外。