Hi,
I’ve uploaded Microsoft Word docs to a MySql database and stored them as binary files. But when I download a file and try to display it in a browser (Firefox or IE) illegible characters are displayed. I’ve tried altering collations and character sets but to no avail. The same thing happens if I upload other types of files, e.g. gif, jpg images, etc. When I download I get a few illegible characters. Here is the PHP code for downloading a file:
<?php
$con = mysql_connect("hostserver",“user","pswd");
if(!$con)
{ die('Could not connect: ' . mysql_error());
}
mysql_select_db("database", $con);
$sql = "SELECT name, type, size, content FROM CVs ".
"WHERE id = 3";
$res = mysql_query($sql) or die('Error, query failed');
list($name, $type, $size, $content) = mysql_fetch_array($res);
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
echo $content;
mysql_close($con);
exit;
?>
I wonder if anyone has any suggestions as to how to rectify the problem. I am completely lost as to what to do next. I would be very grateful for all help.
I’ve uploaded Microsoft Word docs to a MySql database and stored them as binary files. But when I download a file and try to display it in a browser (Firefox or IE) illegible characters are displayed. I’ve tried altering collations and character sets but to no avail. The same thing happens if I upload other types of files, e.g. gif, jpg images, etc. When I download I get a few illegible characters. Here is the PHP code for downloading a file:
<?php
$con = mysql_connect("hostserver",“user","pswd");
if(!$con)
{ die('Could not connect: ' . mysql_error());
}
mysql_select_db("database", $con);
$sql = "SELECT name, type, size, content FROM CVs ".
"WHERE id = 3";
$res = mysql_query($sql) or die('Error, query failed');
list($name, $type, $size, $content) = mysql_fetch_array($res);
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
echo $content;
mysql_close($con);
exit;
?>
I wonder if anyone has any suggestions as to how to rectify the problem. I am completely lost as to what to do next. I would be very grateful for all help.