[英]Yii2 REST API PUT method with images
I am getting issue in PUT
method of YII2
rest api when I pass images otherwise its working fine. 当我通过图像时, YII2
rest api的PUT
方法出现问题,否则工作正常。 In POST
request its working fine. 在POST
要求其正常工作。
Below is my code 下面是我的代码
/**
* Funcion to update existing product by productID
*
* @return type
*/
public function actionUpdate($id) {
$request = Yii::$app->request;
$post = $request->post();
$params = Yii::$app->request->bodyParams;
print_r($params);
die;
$model = Product::findOne($id);
$images = $model->uploadProductImages($_FILES);
$post['images'] = implode(",", $images);
$model->updateProduct($id, $post);
return $post;
}
When I try with images below is the output I get. 当我尝试下面的图像时,我得到的输出。
Array
(
[-----------------------------16309270534592
Content-Disposition:_form-data;_name] => "name"
TESTP11APR
-----------------------------16309270534592
Content-Disposition: form-data; name="sku"
SKUTESTP11APR
-----------------------------16309270534592
Content-Disposition: form-data; name="images"; filename="Koala.jpg"
Content-Type: image/jpeg
????
)
And I remove the image fields from swagger then proper data I get. 然后从大摇大摆中删除图像字段,然后获取正确的数据。 What will the issue. 有什么问题。
PHP provides support for the HTTP PUT method used by some clients to store files on a server. PHP支持某些客户端使用HTTP PUT方法将文件存储在服务器上。
PUT /path/filename.html HTTP/1.1
The following code is in the php documention for uploading files via PUT: 以下代码位于php文档中,用于通过PUT上传文件:
<?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);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.