Ok, check /app/config/app.php to be sure that debug
is set to true
then, if this is still your table structure:
CREATE TABLE docs (
gov_docs_id int(11) NOT NULL AUTO_INCREMENT,
personnel_id int(11) DEFAULT NULL,
docs_name varchar(255) DEFAULT NULL,
docs_num int(11) DEFAULT NULL,
docs_date datetime DEFAULT NULL,
filename varchar(255) DEFAULT NULL,
data longblob,
PRIMARY KEY (gov_docs_id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Change it, to add the columns size
and mime
, just run these commands in a MySQL client:
alter table docs add size int unsigned not null default 0;
alter table docs add mime varchar(255) not null;
Then change your code to:
Route::get('/getfile/{id}', function($id)
{
$file = DB::select('SELECT * FROM docs WHERE gov_docs_id = ?', array($id));
$data = $file[0]->file;
return Response::make($data, 200, array('Content-type' => $file[0]->mime, 'Content-length' => $file[0]->size));
});
In order to work fine you have to change also the script used to save the file to the database and add the mine
and size
columns:
$mime = Input::file('upload')->getMimeType();
$size = Input::file('upload')->getSize();
DB::table('docs')->insert(array(
'doc_attachment'=> $data,
'mime' => $mime,
'size' => $size
)
);
Remember to change tablename
to your current table name (i.e. docs
), and also refer to the correct id, which in your table is gov_docs_id
. If the problem persists check che error log in /app/storage/logs/
and Apache error log.