4

我正在尝试使用 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');

如何获取内容以便进行编码?

4

1 回答 1

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);
于 2012-10-26T22:12:05.243 回答