PHP多文件上传器仅上传单个文件

时间:2018-06-08 13:32:19

标签: php

我已经浏览了S.O几个小时,仍然无法弄清楚为什么我的代码无效。我正在尝试上传多个音乐文件,但出于某种原因,只有1个文件被上传。

这是我的代码:

HTML

<input id="songs" name="songs[]" type="file" multiple="multiple" accept=".ogg,.flac,.mp3" />

PHP

$path = "../songs/"; //file to place within the server
$valid_formats1 = array("mp3", "ogg", "flac"); //list of file extention to be accepted
$tot = count($_FILES['songs']['name']);

for($i = 0; $i < $tot ; $i++){
    $temporaryPathOfImage = $_FILES['songs']['tmp_name'][$i];

    if ($temporaryPathOfImage != ""){
        $dirPath = "../songs/" . $_FILES['songs']['name'][$i];

        if(move_uploaded_file($temporaryPathOfImage, $dirPath)) {
          echo "Stored in: " . "../songs/" . $_FILES['songs']['name'][$i];
        }
    }
}

0 个答案:

没有答案