Page 1 of 1
files downloaded from DB are corrupt
Posted: Mon Jan 11, 2010 6:42 am
by NikBruce
Hi, when ever I download blobs from my DB I can't open them. I get I warning telling me that the files are either corrupt, damaged, truncated, or incomplete.
I can open txt and mp3 files.
I did open the damaged image files in photoshop, but I can only partially view them. So they are indeed damaged.
Is there a way to prevent the file corruption?
Thanks.
Re: files downloaded from DB are corrupt
Posted: Mon Jan 11, 2010 12:39 pm
by Darhazer
You have error at line 117
Seriously, if you expect an answer, show your download code. And make sure that the blobs are inserted in the database correctly.
Re: files downloaded from DB are corrupt
Posted: Mon Jan 11, 2010 4:51 pm
by NikBruce
hahahahaha my bad.
This is the upload code:
Code: Select all
$name = $_FILES['fileUpload']['name'];
$name = str_replace(" ","_", $name);
$mime = $_FILES['fileUpload']['type'];
$data = file_get_contents($_FILES ['fileUpload']['tmp_name']);
$size = intval($_FILES['fileUpload']['size']);
$tmpName = $_FILES['fileUpload']['tmp_name'];
$ti = "INSERT INTO `$proName` (name, mime, size, data, createdDate, createdBy, discription)
VALUES ('$name', '$mime', '$size', $data, '$date', '$accName', '$discription')";
$result = mysql_query($ti) or die(mysql_error());
This is the download code:
Code: Select all
if(!is_numeric($id)) { die("Invalid id specified"); }
$sql = "SELECT `mime`, `data`, `size`, `name` FROM `$proName` WHERE `id` = '$id'";
$result = mysql_query($sql) or die(mysql_error());
$count = mysql_num_rows($result);
if($count == 1)
{
while($row = mysql_fetch_array($result))
{
$mime = $row["mime"];
$data = $row["data"];
$size = $row["size"];
$name = $row["name"];
header("Content-type: $mime");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-transfer-encoding: binary");
echo $data;
}//from the while loop
}//from if($count == 1)
else { echo "Record doesn't exist."; }
Re: files downloaded from DB are corrupt
Posted: Wed Jan 13, 2010 3:20 am
by NikBruce
solution:
the variables from the upload script were on a separate page to the rest of the upload script, and then passed along using a session. It will not work this way. they must be on the same page.