这可能吗 ?
这是有模型的
CUploadedFile::getInstance($model,'newsimage');
$model->image->saveAs("image\path")
但我不想创建模型只是为了保存我的图像。
我实际上需要这个的目的是......我正在尝试使 CKEditor 的“上传图像”功能正常工作,但我需要一个用于图像保存的脚本。
当我单击“上传图像”按钮时,我只需调用一个操作,然后从那里我可以使用以下命令访问我选择的图片$_FILES
,但我似乎无法将文件保存到目标目录。
是否可以将文件保存到目标路径(例如“C:\myProject\images”)而不使用模型?
EDIT :
这是我稍后找到的解决方案
我上传的文件位于$_FILES['upload']
so ..
$temp = CUploadedFile::getInstanceByName("upload"); // gets me the file into this variable ( i gues this wont work for multiple files at the same time )
$temp->saveAs("D:/games/" . $temp->name); // full name , including the filename too.
假设“没有模型”=“没有数据库表”
您只需在模型目录中创建一个从 CFormModel 扩展的 UploadForm.php
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',
);
}
}
并在你的控制器中
$model->upload_file=CUploadedFile::getInstance($model,'upload_file');
$model->upload_file->saveAs("C:\myProject\images\".$model->upload_file->name)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)