Yii upload to local file path
23,444
Solution 1
$images_path = realpath(Yii::app()->basePath . '/../images');
$model->image->saveAs($images_path . '/' . $model->image);
Solution 2
Yii way of doing it will be using YiiBase::getPathOfAlias() which translate an alias to its corresponding path.
Yii predefine these alias
system: refers to the Yii framework directory;
zii: refers to the Zii library directory;
application: refers to the application's base directory;
webroot: refers to the directory containing the entry script file.
ext: refers to the directory containing all third-party extensions.
So using
$imagePath = YiiBase::getPathOfAlias("webroot").'/images';
will give you required results.
Comments
-
Abudayah about 4 years
I need to upload images to images path in my local site.. how can me write path ?
error: $model->image->saveAs('/app/images');
images path C:\xampp\htdocs\worldi\app\images