Saving and Loading ( download back ) a file

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

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;


}

Nice stuff, I didn’t knew, thank you very much for pointing!