Hi,
I am trying to add a REST api to be used by mobile applications to upload image/audio file. I am trying to use PUT method to get the image/file data from the http form-data, but for some reason the fopen("php://input", "r"); returns empty stream. I tried the code as give in this sample http://www.php.net/manual/en/features.file-upload.put-method.php.
Meanwhile, using POST method works though. Using the following code for POST
$putdata = fopen($_FILES['photo']['tmp_name'], "r");
$filename = $this->documentPath.uniqid().'.jpg';
/* Open a file for writing */
$fp = fopen($filename, "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);
How to get the file/image data using PUT method? Many recommend PUT in REST API for uploading data, but I am not sure why. Any thoughts?