2012-01-15 129 views
4

我需要将图片上传到我的本地站点的图片路径中。 我该怎么写路径?Yii上传到本地文件路径

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

图像路径 C:\ XAMPP \ htdocs中\ worldi \应用\图像

回答

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

做它的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. 

因此,使用

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

会给你需要的结果。