In this guide Uploading Files is there some point not clear for me.
I created the model "models/UploadForm.php", then the view "views/upload/index.php" and the controller "controllers/UploadFormController.php". The files content is the same of the guide, but going to "www.mysite.com/upload" the "(#404) Unable to resolve the request "upload"." error occurs.
I’m really, really sorry but still don’t understand. Please be patient.
This is my /models/Upload.php
<?php
namespace app\models;
use yii\base\Model;
use yii\web\UploadedFile;
/**
* UploadForm is the model behind the upload form.
*/
class Upload extends Model
{
/**
* @var UploadedFile|Null file attribute
*/
public $file;
/**
* @return array the validation rules.
*/
public function rules()
{
return [
[['file'], 'file'],
];
}
}
?>
<?php
namespace app\controllers;
use Yii;
use yii\web\Controller;
use app\models\Upload;
use yii\web\UploadedFile;
class SiteController extends Controller
{
public function actionUpload()
{
$model = new Upload();
if (Yii::$app->request->isPost) {
$model->file = UploadedFile::getInstance($model, 'file');
if ($model->validate()) {
$model->file->saveAs('uploads/' . $model->file->baseName . '.' . $model->file->extension);
}
}
return $this->render('index', ['model' => $model]);
}
}
?>
On running “www.mysite.com/upload/” this code return “Unknown class - Unable to find ‘app\controllers\UploadController’ in file: /var/www/mds/controllers/UploadController.php. Namespace missing?”
Changing "class SiteController extends Controller" to "class UploadController extends Controller" return "Unable to resolve the request: upload/"