Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: PDF Blob Error

  1. #1
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #3
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •