2015-08-16 110 views
1

下面的代碼將使用HTTP PUT方法上傳一個文件:上傳多個HTTP PUT文件PHP

/* PUT data comes in on the stdin stream */ 
$putdata = fopen("php://input", "r"); 

/* Open a file for writing */ 
$fp = fopen("myputfile.ext", "w"); 

/* Read the data 1 KB at a time 
and write to the file */ 
while ($data = fread($putdata, 1024)) 
fwrite($fp, $data); 

/* Close the streams */ 
fclose($fp); 
fclose($putdata); 

如何修改上面上傳兩個文件?

回答

0

我沒有測試過這一點,所以只是知道,但也許使用的功能,你可以用你的代碼和飼料將更改它,即目的地:

<?php 

    function SaveFile($fromFile = false,$tofile = false) 
     { 
      if(empty($fromFile) || empty($tofile)) 
       return false; 

      /* PUT data comes in on the stdin stream */ 
      $putdata = fopen($fromFile, "r"); 

      /* Open a file for writing */ 
      $fp = fopen($tofile, "w"); 

      /* Read the data 1 KB at a time 
      and write to the file */ 
      while ($data = fread($putdata, 1024)) 
      fwrite($fp, $data); 

      /* Close the streams */ 
      fclose($fp); 
      fclose($putdata); 

      return true; 
     } 

$files[] = array("get"=>"php://input1","put"=>"myputfile1.ext"); 
$files[] = array("get"=>"php://input2","put"=>"myputfile2.ext"); 

foreach($files as $files) 
    { 
     SaveFile($files['get'],$files['put']); 
    } 

?>