Hello!
I've got a quick question, and I'm sure the answer's out there somewhere. :-)
I currently have a form that's storing user uploads to the database as BLOB's, this data (currently) can be anything from PDF's, to Word DOC's, etc...
My problem is that unless I zip it, MySQL tends to corrupt the document somehow (Line breaks? I dunno). I'm not even sure if Zipping will be 100% effective, or only on the times I've tried.
What am I doing wrong? Here's my storage code:
// Add to database
$data = addslashes(fread(fopen($userfile, "r"), filesize($userfile)));
$sql = "SELECT ID FROM FileGroup WHERE Description='" . $Group . "'";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
$sql = "INSERT INTO File
(FileName, Uploader, Comment, GroupID, BinData, Date, FileSize, FileType)
VALUES('" . $userfile_name . "', '" . $SUsername . "', '" . addslashes($Comments) . "', '" . $row[0] . "', \"" . $data . "\", '" . date("Y-m-d H:i:s") . "', '" . filesize($userfile) . "', '" . $userfile_type . "')";
mysql_query($sql) or die("Couldn't add to database! $sql");
And my output:
$sql = "SELECT FileName,
BinData,
FileType
FROM File
WHERE ID=" . $FILEID;
$result = mysql_query($sql) or die("Echoing: <BR> $sql");
$data = mysql_result($result,0,"BinData");
$type = mysql_result($result,0,"FileType");
Header( "Content-type: application/download\n");//$type");
Header( "Content-Disposition: filename=" . mysql_result($result,0,"FileName"));// attachment; filename=" . mysql_result($result,0,"FileName"));
echo $data;
This sound right? Please let me know!
KZ