st3fanus
(St3fanus Solution)
May 11, 2011, 4:52am
1
Hi…
I want to ask about my case :
I have saved a word ( .doc ) file into DB (Mysql) in BLOB Field. And then i want to loading back as download it into .doc file again.
Could anyone help me ? ( explanation, code, or example ,etc )
thanks a lot
Stefanus
God Bless You
zaccaria
(Matteo Falsitta)
May 11, 2011, 1:51pm
2
Create a dedicated action like that:
public function actionDownloadDoc($id)
{
$file= Files::model()->findByPk($id);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=file.doc');
header('Content-Transfer-Encoding: binary');
header('Content-Transfer-Encoding: binary');
header('Content-type: application/msword');
echo $file->blobField;
}
Asgaroth
(Asgaroth Belem)
May 11, 2011, 2:22pm
3
zaccaria:
Create a dedicated action like that:
public function actionDownloadDoc($id)
{
$file= Files::model()->findByPk($id);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=file.doc');
header('Content-Transfer-Encoding: binary');
header('Content-Transfer-Encoding: binary');
header('Content-type: application/msword');
echo $file->blobField;
}
What about the yii way?
http://www.yiiframework.com/doc/api/1.1/CHttpRequest/#sendFile-detail
or
http://www.yiiframework.com/doc/api/1.1/CHttpRequest/#xSendFile-detail
It would be something like:
public function actionDownloadDoc($id)
{
$file= Files::model()->findByPk($id);
Yii::app()->request->sendFile($file->fileName,$file->blobField,$$file->mimeType);
echo $file->blobField;
}
zaccaria
(Matteo Falsitta)
May 11, 2011, 2:25pm
4
Nice stuff, I didn’t knew, thank you very much for pointing!