Yii , saving an image from $_FILES , but without using models

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 06:54:25

Assuming that "without model"="without a db table"

You Just make a UploadForm.php extending from CFormModel in your models directory

class UploadForm extends CFormModel
{
    public $upload_file;

    public function rules()
    {
        return array(
        array('upload_file', 'file', 'types'=>'jpg,jpeg,gif,png','maxSize'=>10*1024*1024),
        );
    }

    /**
     * Declares attribute labels.
     */
    public function attributeLabels()
    {
        return array(
            'upload_file'=>'Upload File',
        );
    }

}

and in your controller

$model->upload_file=CUploadedFile::getInstance($model,'upload_file');
$model->upload_file->saveAs("C:\myProject\images\".$model->upload_file->name)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!