2012-01-03 63 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