I have a project in which I desire to upload and download blob files in php. I have written the codes to upload the files into mysql however, when I try to download the files, be it pdf, .doc or jpeg, the error message I get is "The selected file can not be opened". I need assistance in this regard pls. The download codes are:
PHP Code:
<?php
if(isset($_GET['download']))
{
// if id is set then get the file with the id from database
include 'open_db.inc';
$name = $_GET['download'];
$query = "SELECT name, type, size, content " .
"FROM upload WHERE name = '$name'";
$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) = mysql_fetch_array($result);
header("Cache-Control: maxage=1"); //In seconds
header("Pragma: public");
header("Content-length:$size");
header("Content-type:$type");
header("Content-type:application/pdf");
header("Content-Disposition: attachment;filename=\"$name\"");
header("Content-Description: PHP Generated Data");
header("Content-transfer-encoding: binary");
ob_end_clean();
echo $size;
echo $type;
$content = stripslashes ($content);
echo $content;
exit;
}
?>
omoayan 0 Newbie Poster
arcticM
omoayan 0 Newbie Poster
sasankasekhar 0 Newbie Poster
omoayan 0 Newbie Poster
sasankasekhar 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.