如何移动上传的文件

时间:2012-10-19 16:05:47

标签: php html

我有一个HTML网页表单,用户可以上传多个文件。我在移动文件方面遇到了麻烦。

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>

Save.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()。我能做错什么?

1 个答案:

答案 0 :(得分: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;
 }