我想從郵遞員表單數據上傳圖像。我不能讓輸入Yii框架webservice上傳圖像郵遞員
URL: localhost/sampleyii/web-app/web/imageuploads
Method: POST
{"Content-Type":"application/x-www-form-urlencoded"}
Form-data
id : 2
image : test.jpg (type:file)
在我的警予編碼:
Array
(
[------WebKitFormBoundarySHaGMA86OHQV87iT
Content-Disposition:_form-data;_name] => "id"
sdfgdfgdf
------WebKitFormBoundarySHaGMA86OHQV87iT
Content-Disposition: form-data; name="wretr"; filename="test.jpeg"
Content-Type: image/jpeg........
....................
我已經試過的Content-Type => '的multipart/form-data的':從郵遞員
$model = new TblImgUpload();
print_r(Yii::$app->request->post());
$model->load(Yii::$app->request->post(),'');
響應。但我不能得到輸入請求。
我想將post請求輸入作爲form-data(file)作爲數組。
請提前幫助感謝。
您好,感謝您快速回復。我已經嘗試了上面的代碼並在郵差中測試過。它不工作。以下是郵寄員使用表單數據進行的回覆。 { 「imageFile」:null }。請幫忙?? –
是的,它應該是'multipart/form-data'而不是'x-www-form-urlencoded'。我的代碼中的imageFile是應該上傳文件的字段的名稱。我認爲在你的情況下,該字段被稱爲'wretr'。另外嘗試取消其他字段的設置,但我對此知之甚少,但[Content-Disposition:_form-data; _name] =>「id」'對我來說很奇怪。我可能是錯的,但我通常將其視爲「內容處置:表單數據; name =「id」' –