gpt4 book ai didi

php - PATCH/PUT 不接受多部分/表单数据文件上传?

转载 作者:可可西里 更新时间:2023-11-01 13:24:12 26 4
gpt4 key购买 nike

知道为什么 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 ):

<?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);
?>

关于php - PATCH/PUT 不接受多部分/表单数据文件上传?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28791057/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com