小编app*_*der的帖子

yii2 REST Api 使用 PUT 上传文件

我正在尝试在 Yii2 中添加 REST api 供移动应用程序用来上传图像/音频文件。我试图使用 PUT 方法从 http 表单数据获取图像/文件数据,但由于某种原因 fopen("php://input", "r"); 返回空流。我尝试了此示例中给出的代码http://www.php.net/m...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);
?>
Run Code Online (Sandbox Code Playgroud)

同时,使用 POST 方法也可以。使用以下代码进行 POST

$putdata = fopen($_FILES['photo']['tmp_name'], "r");
        $filename …
Run Code Online (Sandbox Code Playgroud)

php rest yii2

4
推荐指数
1
解决办法
8209
查看次数

标签 统计

php ×1

rest ×1

yii2 ×1