2012-01-03 65 views
0

我正在創建一個接收文件(圖像)和其他數據的Web服務。PHP:重新處理上傳的文件

問題是PHP如何處理它?我讀過一些文章,說我應該使用PUT方法。你如何閱讀它? http://input? POST?文件?

+0

有用的問題:http://stackoverflow.com/questions/359047/php-detecting-request-type-get-post-put-or-delete – diEcho 2012-01-03 05:25:25

+0

@diEcho感謝的人。但我已經知道了。只是處理上傳的文件。 – sheeks06 2012-01-04 04:10:48

回答

2

Reference

<?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

pst ... [stream_copy_to_stream()](http://www.php.net/stream_copy_to_stream())或甚至只是[copy()](http://www.php.net/copy()) – goat 2012-01-03 05:47:32

+0

還行。作爲後續,如何使用shell grep測試這個?它會是>> grep --upload-file @/some/file/doc.txt https://myapi.com/file – sheeks06 2012-01-04 04:06:25