【发布时间】:2016-03-10 17:27:04
【问题描述】:
我正在尝试从 Yii 框架中的注册表单上传图片。图像将保存在“img/avatar”文件夹中,图像名称应更改为用户名。我为此使用的代码如下:
//uploading avatar to the img/avatar folder
$upload_file = CUploadedFile::getInstance($personModel, 'picture');
$personModel->picture = $upload_file;
$picture_name = $userModel->username;
$personModel->picture = $picture_name;
if(isset($upload_file))
{
$upload_file->saveAs(Yii::app()->basePath.'/../img/avatar'.$picture_name);
}
$personModel->save();
//end of image uploading part
问题是:用户名的名字已经保存在数据库的图片行中。但是图像没有上传到文件夹中。我试图找出代码中的问题。但无法解决。有什么建议吗?
【问题讨论】:
-
请使用此链接,它可以帮助您[如何上传图片] (yiiframework.com/wiki/349/…)
-
我看过教程。但无法解决。
-
这里缺少在文件名中添加扩展名
-
您确定用户名具有有效符号以将文件名存储在磁盘上吗?首先,您需要去除错误的字符。 @MuminurRahman
标签: php yii image-uploading yii-cactiverecord yii-cformmodel