无法使用 PUT 方法上传图像

can not upload image using PUT method

我想问一下,在我休息之前 api 用 POST 方法的图片上传功能是有效的,但是当我想尝试使用 PUT 方法来制作更新功能时就很合适它失败了。 响应始终为空图片继续。 我想问一下 PUT 方法是否不同 perlakuaanya? 我使用 $ _FILES ["image"] 来捕获上传数据。 这是错的吗? 提前谢谢你。

嗯,PHP official document of $_FILES清楚了:

An associative array of items uploaded to the current script via the HTTP POST method. The structure of this array is outlined in the POST method uploads section.

$_FILES 只接受 "POST" 方法,因此您不能使用它通过 HTTP PUT 获取文件。

通过"PUT"方式获取文件,需要使用php://input流,请参考PUT method support,官方举例:

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