知道为什么 PATCH 和 PUT 不接受多部分/表单数据文件上传吗?
当我跑步时var_dump($_FILES)
它输出array(0) { }
。有什么想法为什么会发生这种情况吗?如果我发布文件,它工作正常。
以下是我正在运行的请求的示例。
提前致谢!
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__--
使用 PUT 请求上传文件时,您不使用 multipart/form-data。 PUT 请求与 GET 请求几乎相同。您应该做的就是将文件的内容放入请求正文中。之后,您可以使用以下代码检索文件,如 php 文档中所述:
http://php.net/manual/en/features.file-upload.put-method.php 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);
?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)