此函数仅上传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
答案 0 :(得分:1)
将return $fileDirectories;
语句移到for循环之外。