0

我有一个 HTML Web 表单,用户可以在其中上传多个文件。我在移动文件时遇到了麻烦。

HTML:

我的 HTML:

<form enctype="multipart/form-data" method="post" action="save.php">
    <input type="hidden" name="MAX_FILE_SIZE" value="500000"/>
    <input type="file" name="uploads[]" multiple="multiple" />
    <input type="submit" name="submit" value="submit"/>
 </form>

保存.php:

 <?php
     foreach ($_FILES['uploads']['name'] as $file) {
     $target= UPLOADPATH . $file;
     move_uploaded_file($file, $target)
     or die('error with moving the file');
      $file= time() . $_FILES['uploads']['name'];
         echo $file;
     }

问题在于 move_uploaded_file()。我可能做错了什么?

4

1 回答 1

2

尝试如下,您需要将第一个参数作为文件源传递

foreach ($_FILES['uploads']['name'] as $key => $file) {
 $target= UPLOADPATH . $file;

 move_uploaded_file($_FILES['uploads']['tmp_name'][$key], $target)
 or die('error with moving the file');
  $file= time() . $_FILES['uploads']['name'];
     echo $file;
 }
于 2012-10-19T16:10:36.900 回答