Yii上传到本地文件路径

问题描述 投票:4回答:2

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

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

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

php file-upload yii
2个回答
18
投票
$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';

会给你所需的结果。

© www.soinside.com 2019 - 2024. All rights reserved.