Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3667

PHP multipart form data PUT request?

$
0
0

I'm writing a RESTful API. I'm having trouble with uploading images using the different verbs.

Consider:

I have an object which can be created/modified/deleted/viewed via a post/put/delete/get request to a URL. The request is multi part form when there is a file to upload, or application/xml when there's just text to process.

To handle the image uploads which are associated with the object I am doing something like:

    if(isset($_FILES['userfile'])) {        $data = $this->image_model->upload_image();        if($data['error']){            $this->response(array('error' => $error['error']));        }        $xml_data = (array)simplexml_load_string( urldecode($_POST['xml']) );                   $object = (array)$xml_data['object'];    } else {        $object = $this->body('object');    }

The major problem here is when trying to handle a put request, obviously $_POST doesn't contain the put data (as far as I can tell!).

For reference this is how I'm building the requests:

curl -F userfile=@./image.png -F xml="<xml><object>stuff to edit</object></xml>"  http://example.com/object -X PUT

Does anyone have any ideas how I can access the xml variable in my PUT request?


Viewing all articles
Browse latest Browse all 3667

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>