PHP multipart form data PUT request?

后端 未结 5 1258
南笙
南笙 2020-11-29 06:35

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/del

5条回答
  •  无人及你
    2020-11-29 07:35

    Quoting netcoder reply : "Take note the above will only work for multipart content types"

    To work with any content type I have added the following lines to Mr. netcoder's solution :

       // Fetch content and determine boundary
       $raw_data = file_get_contents('php://input');
       $boundary = substr($raw_data, 0, strpos($raw_data, "\r\n"));
    
       /*...... My edit --------- */
        if(empty($boundary)){
            parse_str($raw_data,$data);
            return $data;
        }
       /* ........... My edit ends ......... */
        // Fetch each part
        $parts = array_slice(explode($boundary, $raw_data), 1);
        $data = array();
        ............
        ...............  
    

提交回复
热议问题