我正在尝试使用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');
如何获取内容以便我可以进行编码?
答案 0 :(得分:5)
这样做:
$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);