简体   繁体   中英

How to move an uploaded file

I have an HTML web form where users can upload multiple files. I am having trouble with moving the files though.

HTML:

My 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;
     }

The problem is with move_uploaded_file(). What could I be doing wrong?

Try as below, you need to pass first parameter as file source

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;
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM