Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-01-2010, 08:43 PM   PM User | #1
Downugo
New to the CF scene

 
Join Date: Sep 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Downugo is an unknown quantity at this point
PDF Blob Error

Hello,
I have been able to upload a pdf and store it in the mysql database table. In phpMyAdmin I can verify that the pdf is the correct size. However when I try to download the file the document comes back blank and I get an error saying that acrobat could not open the file 'filename.pdf' because it is either not a supported file type or because the file has been damaged. The download code:
<?php
if(isset($_GET['nid'])){
$nid = mysql_real_escape_string($_GET['nid']);
$sql = "SELECT name,type,size,article FROM newsarticles WHERE newsid='$nid' AND active=0";
$result = mysql_query($sql);
$data = mysql_result($result, 0, "article");
$name = mysql_result($result, 0, "name");
$size = mysql_result($result, 0, "size");
$type = mysql_result($result, 0, "type");
//die ("The name is $name, the size is $size and the type is $type.");
header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: PHP Generated Data");
echo $data;
}?>

The query is working correctly because the die line has the correct information for the article.

Why am I unable to correctly download the pdf which has been stored as a blob?

Thanks in advance,
- Scott
Downugo is offline   Reply With Quote
Old 11-01-2010, 09:37 PM   PM User | #2
Downugo
New to the CF scene

 
Join Date: Sep 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Downugo is an unknown quantity at this point
So it looks like it IS a problem with the uploading. The size field was getting entered correctly but the size of the blob was 0. I separated the code for the pdf upload onto it's own page and now it's not even getting the correct size.

if(isset($_POST['upload'])){
if ($_FILES['userfile']['size'] > 0){
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc()) $fileName = addslashes($fileName);

$newsid = $_POST['attach'];

if ($fileSize>2000000) $msg = "<div class=\"failed\">The file is too large!</div>";
else {
$query = "REPLACE INTO newsarticles (newsid, name, type, size, article, user) VALUES ('$newsid', '$fileName', '$fileType', '$fileSize', '$content', '$uid')";
die ($query);
if (!mysql_query($query))$msg = "<div class=\"failed\">There was an error uploading the pdf!</div>";
else $msg = "<div class=\"success\">The new pdf was successfully uploaded!</div>";
}
}
else $msg = "<div class=\"failed\">No data for upload!</div>";
}

The newsid is working correctly and the name and type are correct, however the size is always 1 and the blob is always empty. Can anyone spot my error?
Downugo is offline   Reply With Quote
Old 11-02-2010, 11:16 PM   PM User | #3
Downugo
New to the CF scene

 
Join Date: Sep 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Downugo is an unknown quantity at this point
So it was just something with uploading the pdf, the size field was getting calculated correctly but the actual blob data was not getting uploaded properly. It seems to be working now.
Downugo is offline   Reply With Quote
Reply

Bookmarks

Tags
blob, error, mysql, pdf

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:13 PM.


Advertisement
Log in to turn off these ads.