Rest Api File Upload With Put

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?

Hi,

did u find any solution?

Not yet…

Could "the empty stream" be a consequence of php://input whith a php version older than 5.6? At php.net/manual/en/wrappers.php.php is written: