I have used some example code to create a database in MySQL and using
php I can add binary files to the database. I was under the impression
that I would be able to download the files with the source code
provided, but am having trouble doing that.
<?php
if ($id_files) {
include "./include/open_db.inc";
$sql = "SELECT bin_data, filetype, filename, filesize FROM tbl_Files
WHERE id_files=$id_fi les";
$result = @mysql_query($s ql, $db);
$data = @mysql_result($ result, 0, "bin_data") ;
$name = @mysql_result($ result, 0, "filename") ;
$size = @mysql_result($ result, 0, "filesize") ;
$type = @mysql_result($ result, 0, "filetype") ;
header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name" );
header("Content-Description: PHP Generated Data");
echo $data;
}
?>
I thought I would be greeted with a dialog box asking me where i want to
save my file.
Am I getting the wrong impression?
How would I go about downloading the data from database?
Thanks.
php I can add binary files to the database. I was under the impression
that I would be able to download the files with the source code
provided, but am having trouble doing that.
<?php
if ($id_files) {
include "./include/open_db.inc";
$sql = "SELECT bin_data, filetype, filename, filesize FROM tbl_Files
WHERE id_files=$id_fi les";
$result = @mysql_query($s ql, $db);
$data = @mysql_result($ result, 0, "bin_data") ;
$name = @mysql_result($ result, 0, "filename") ;
$size = @mysql_result($ result, 0, "filesize") ;
$type = @mysql_result($ result, 0, "filetype") ;
header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name" );
header("Content-Description: PHP Generated Data");
echo $data;
}
?>
I thought I would be greeted with a dialog box asking me where i want to
save my file.
Am I getting the wrong impression?
How would I go about downloading the data from database?
Thanks.
Comment