2008年10月22日星期三

[fw-db] Getting JPEGs from DB

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.

没有评论: