Re: storing files in database and retriving them
| From: | Peter Lind | Date: | Tue, 27 Jul 2010 13:16:02 +0000 |
| Subject: | Re: storing files in database and retriving them | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-307168@lists.php.net to get a copy of this message | ||
2010/7/27 Nilesh Govindarajan <lists@itech7.com>:
> 2010/7/27 Dušan Novaković <ndusan@gmail.com>:
>> Hello,
>>
>> so when I'm sending the array to model it's like this:
>>
>> $fp = fopen(INVOICE_PATH.date('Y-m-d').DS.$pdfName, "r");
>> $pdfContent = array(
>> 'file' =>
>> base64_encode(fread($fp,
>> filesize(INVOICE_PATH.date('Y-m-d').DS.$pdfName))),
>> 'name' =>
>> $pdfName,
>> 'size' =>
>> filesize(INVOICE_PATH.date('Y-m-d').DS.$pdfName),
>> 'type' =>
>> mime_content_type(INVOICE_PATH.date('Y-m-d').DS.$pdfName)
>> );
>> fclose($fp);
>>
>> so the data in db are ok, and this type is application/pdf.
>>
>> And when I'm getting data, I get the array like this:
>>
>> $file = Array
>> (
>> [id] => 2
>> [file] =>VBERi0xLjM... <= here file is base64_encode()
>> [file_size] => 2204
>> [file_type] => application/pdf
>> [file_name] => 2_file.pdf
>> )
>>
>> Headers:
>>
>> header("Content-length: ".$file['file_size']);
>> header("Content-type: ".$file['file_type']);
>> header("Content-Disposition: attachment; filename=
>> ".$file['file_name']);
>> echo base64_decode($file['file']);
>>
>>
>> So, mime looks ok, but still... not working :-(
>>
>>
>>
>>
>> --
>> mob: + 46 70 044 9432
>> web: http://novakovicdusan.com
>>
>> Please consider the environment before printing this email.
>>
>
> Are you sure that you need Content-Disposition? Try removing that. I
> think that's used only in emails (Correct me if I'm wrong).
You're wrong. Content-Disposition tells the browser how to handle the
content - in this case, the browser will download the file instead of
displaying it.
Regards
Peter
--
<hype>
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
</hype>