Closed sinergycode closed 6 years ago
Hi @sinergycode!
The problem is in your action code. You should use the predefined action in the controller like this:
public function actions()
{
return [
'native-imperavi' => [
'class' => 'vova07\imperavi\actions\UploadFileAction',
'url' => 'http://site.com/public_html/uploads/images/blog/',
'path' => '@alias/to/my/path'
]
];
}
Note: You should specify the path
where the files will be uploaded.
The code from view
didn't change.
In case you still have problems, feel free to re-open this issue.
Thanks it's working, but not enought. The request body is also empty.
@sinergycode nope, I mean you should add the external
action into your controller.
In case you wanna do it as you do you should copy-paste the code from UploadFileAction
.
Let's use for example the SiteController
from yii2-app-basic
template.
In that controller we have such actions()
method:
/**
* @inheritdoc
*/
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
}
In your case you need to add in that method one more action, to get in final something like this:
/**
* @inheritdoc
*/
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
'native-imperavi' => [
'class' => 'vova07\imperavi\actions\UploadFileAction',
'url' => 'http://site.com/public_html/uploads/images/blog/',
'path' => '@app/uploads/images/blog'
]
];
}
After that you code should start working as expecting.
Note: In case you don't have that action in your controller, you should add it with at least one action: native-imperavi
.
Code:
action:
view:
Yii2 debuger: method: 'POST' isAjax: true Route: 'site/native-imperavi' Action: 'backend\controllers\SiteController::actionNativeImperavi()' $_FILES - file [ 'name' => 'aaaaa.png' 'type' => 'image/png' 'tmp_name' =>'E:\Opse\OSPanel\userdata\temp\php961C.tmp' 'error' => 0 'size' => 99568 ] Request Body: Empty.
Help me please.