I try to upload an image via the postman extension, but I get the following response. Furthermore, the image does not appear in the specified directory.
{
"name": "PHP Notice",
"message": "Undefined index: user_id",
"code": 8,
"type": "yii\\base\\ErrorException",
"file": "C:\\xampp\\htdocs\\basic14-4-2016\\controllers\\ApiuploadsController.php",
"line": 85,
"stack-trace": [
"#0 C:\\xampp\\htdocs\\basic14-4-2016\\controllers\\ApiuploadsController.php(85): yii\\base\\ErrorHandler->handleError(8, 'Undefined index...', 'C:\\\\xampp\\\\htdocs...', 85, Array)",
"#1 [internal function]: app\\controllers\\ApiuploadsController->actionNew()",
"#2 C:\\xampp\\htdocs\\basic14-4-2016\\vendor\\yiisoft\\yii2\\base\\InlineAction.php(55): call_user_func_array(Array, Array)",
"#3 C:\\xampp\\htdocs\\basic14-4-2016\\vendor\\yiisoft\\yii2\\base\\Controller.php(151): yii\\base\\InlineAction->runWithParams(Array)",
"#4 C:\\xampp\\htdocs\\basic14-4-2016\\vendor\\yiisoft\\yii2\\base\\Module.php(455): yii\\base\\Controller->runAction('new', Array)",
"#5 C:\\xampp\\htdocs\\basic14-4-2016\\vendor\\yiisoft\\yii2\\web\\Application.php(84): yii\\base\\Module->runAction('apiuploads/new', Array)",
"#6 C:\\xampp\\htdocs\\basic14-4-2016\\vendor\\yiisoft\\yii2\\base\\Application.php(375): yii\\web\\Application->handleRequest(Object(yii\\web\\Request))",
"#7 C:\\xampp\\htdocs\\basic14-4-2016\\web\\index.php(12): yii\\base\\Application->run()",
"#8 {main}"
]
}
If you want to upload image from postman then you can use this way -
In PostMan
In Yii2 code
write this code in controller
$image = \yii\web\UploadedFile::getInstanceByName('image');
Move temp file in $image to your server
You'll get all necessary details in
$image
variable to upload image.