Yii上传到本地文件路径

时间:2012-01-15 13:17:42

标签: php file-upload yii

我需要将图片上传到我本地网站的图片路径。 我怎么写路径?

错误: $模型 - >图像 - >的saveAs( '/应用/图像');

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

2 个答案:

答案 0 :(得分:18)

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

答案 1 :(得分: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';

会给你所需的结果。

相关问题