0

I'm currently creating a web service that receives files(images) and some other data.

The problem is how can PHP 'handle' it? I've read some articles saying i should use PUT method. How do you read it? http://input? POST? FILES?

gianebao
  • 17,718
  • 3
  • 31
  • 40
  • helpful question : http://stackoverflow.com/questions/359047/php-detecting-request-type-get-post-put-or-delete – xkeshav Jan 03 '12 at 05:25
  • @diEcho thanks man. but i already know that. just the handling of the uploaded files. – gianebao Jan 04 '12 at 04:10

1 Answers1

2

From 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);
?>
xkeshav
  • 53,360
  • 44
  • 177
  • 245
  • pst...[stream_copy_to_stream()](http://www.php.net/stream_copy_to_stream()) or even just [copy()](http://www.php.net/copy()) – goat Jan 03 '12 at 05:47
  • ok. as a follow up, how to test this using shell grep? is it going to be >> grep --upload-file @/some/file/doc.txt https://myapi.com/file – gianebao Jan 04 '12 at 04:06