Php 使用Yii、Mysql下载longblob文件(adobe Illustrator或png)
我试图从mysql数据库下载ai/png,但我得到的只是一个空文件。 在表中,我只有id和两个longblob(file_ai,file_png)。 例如,文件adobe illustrator view是:Php 使用Yii、Mysql下载longblob文件(adobe Illustrator或png),php,mysql,yii,Php,Mysql,Yii,我试图从mysql数据库下载ai/png,但我得到的只是一个空文件。 在表中,我只有id和两个longblob(file_ai,file_png)。 例如,文件adobe illustrator view是: echo CHtml::link('<span class="glyphicon glyphicon glyphicon-download-alt" aria-hidden="true"></span>', array('User/downloadFile', '
echo CHtml::link('<span class="glyphicon glyphicon glyphicon-download-alt" aria-hidden="true"></span>',
array('User/downloadFile', 'id' => $file->id, 'ext' => 'application/illustrator'),
$htmlOptions = array('class' => 'toolMes', 'download', 'data-toggle' => 'tooltip', 'data-placement' => 'bottom', 'title' => 'Download Ai'));
希望有您宝贵的建议就足够了您不要重复实际的文件内容 如果您正在数据库中存储图像,则需要在抛出标题后进行回显
echo$file->file\u ai代码>它解决了这个错误。我曾经使用过关于pdf文件的echo,但现在在我设置了强制下载的标题之后,我认为不再使用echo了。谢谢你
public function actionDownloadFile($id, $ext) {
$file = Files::model()->findByPk($id);
if ($ext === 'application/illustrator') {
header("Content-length:" . strlen($file->file_ai));
header("Content-type: " . $ext . "");
header('Content-Disposition: attachment; filename="' . $file->id . '_' . date("Y-m-d") . '.ai"');
} else {
header("Content-length:" . strlen($file->file_png));
header("Content-type: image/png");
header('Content-Disposition: attachment; filename="' . $file->id . '_' . date("Y-m-d") . '"');
}
}