2008年10月23日星期四

Re: [fw-db] Getting JPEGs from DB

You really don't want to do this.  Store the files on the file system and keep data about them in the database instead.  Use a rewrite map or, better, a series of rewrite rules to serve the files directly from your web server instead of using passthrough.  That will bypass your problem entirely and be much more scalable.

-Matt

On Wed, Oct 22, 2008 at 7:54 PM, Mauro Spivak <mauros@gmail.com> wrote:
Hi there,

I'm have a simple form that uploads files to a server and stores them in a MySQL longblob field using the serialize() function. Then, when I want to retrieve them, I just output them with a couple of headers. Now, because of some reason I don't understand, when I do this through Zend Framework It works perfectly with non-image files (such as PDFs, ZIPs, DOCs, etc.) but not with image files (like JPGs, GIFs, PNGs, etc.)

I'll paste part of the code just for reference:

When uploading: 

{...}
$file['contents'] = file_get_contents($form->file->getValue());
{...}

$newFile = New File;

try {
$newFile->insert($file);
} catch (Exception $e) {
die($e->getMessage());
}


When downloading:

$file = New File;
$file = $file->fetchRow("id='".$params['id']."'");
$this->view->file = $file;

header("Content-Type:image/jpeg");
header("Content-Disposition: attachment; filename=".$file->name.".".MimeToExtension($file->type));

$this->view->file = $file;

I'll really appreciate your answer guys.

Mauro.

没有评论: