PATCH / PUT does not accept multi-factor file / data file?

Any idea why PATCH and PUT did not accept multipart / form-data file uploads?

When I ran var_dump($_FILES) , it outputs array(0) { } . Any idea why this is happening? If I LOST the file, it works fine.

Below is an example of the query that I am running.

Thanks in advance!

 PUT /test.php HTTP/1.1 Content-Type: multipart/form-data; boundary=__X_PAW_BOUNDARY__ Host: [redacted] Connection: close User-Agent: Paw/2.1.1 (Macintosh; OS X/10.10.2) GCDHTTPRequest Content-Length: 17961 --__X_PAW_BOUNDARY__ Content-Disposition: form-data; name="avatar"; filename="default.png" Content-Type: image/png PNG [IMAGE DATA] --__X_PAW_BOUNDARY__-- 
+5
source share
1 answer

When downloading files using the PUT request, you do not use multipart / form-data. The PUT request is almost the same as the GET request. All you have to do is put the contents of the file in the request body. After that, you can get a file with the following code, as described in php docs:

http://php.net/manual/en/features.file-upload.put-method.php ):

 <?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); ?> 
+3
source

Source: https://habr.com/ru/post/1214413/


All Articles