我想使用base64在我的数据库中保存上传的照片,但我无法获取数据:
形成:
<?PHP $form=$this->beginWidget('CActiveForm',
array(
'id' => 'upload-form',
'enableAjaxValidation' => false,
'htmlOptions' => array('enctype' => 'multipart/form-data'),
));?>
<?PHP echo $form->fileField($model, 'attachment');?>
控制器:
$model->attributes=$_POST['Post'];
//gives me the filename
$model->attachment=CUploadedFile::getInstance($model,'attachment');
解决方法:
像这样做:
$model->attributes=$_POST['Post'];
//gives me the filename
$tmpfile = CUploadedFile::getInstance($model,'attachment');
$tmpfile_contents = file_get_contents( $tmpfile->tempName );
$model->attachment = base64_encode($tmpfile_contents);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。