php Yii上传到本地文件路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8869897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 05:40:36  来源:igfitidea点击:

Yii upload to local file path

phpfile-uploadyii

提问by Abudayah

I need to upload images to images path in my local site.. how can me write path ?

我需要将图像上传到本地站点中的图像路径。我该如何写路径?

error: $model->image->saveAs('/app/images');

错误:$model->image->saveAs('/app/images');

images path C:\xampp\htdocs\worldi\app\images

图片路径 C:\xampp\htdocs\worldi\app\images

回答by Abudayah

$images_path = realpath(Yii::app()->basePath . '/../images');
$model->image->saveAs($images_path . '/' . $model->image);

回答by Terminal

Yii way of doing it will be using YiiBase::getPathOfAlias() which translate an alias to its corresponding path.
Yii predefine these alias

Yii 的做法是使用 YiiBase::getPathOfAlias() 将别名转换为其相应的路径。
Yii 预定义这些别名

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';

$imagePath = YiiBase::getPathOfAlias("webroot").'/images';

will give you required results.

会给你所需的结果。