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 7 of 7
  1. #1
    New Coder
    Join Date
    Apr 2009
    Location
    San Diego, CA
    Posts
    64
    Thanks
    2
    Thanked 1 Time in 1 Post

    Download corrupts some PDFs

    I have a download script that works well for most files, but a few of the files I am trying to server up always download corrupt somehow. So far, they are all PDFs.

    Out of curiosity, I tried diffing the downloaded file to the version I pulled down over FTP from my site. Appended at the top of the file that I am trying to download and open I see the following:
    Code:
    <br />
    <b>Notice</b>:  ob_clean() [<a href='ref.outcontrol'>ref.outcontrol</a>]: failed to delete buffer. No buffer to delete. in <b>/home1/trellis1/public_html/supportcb/cns-lib.php</b> on line <b>357</b><br />
    So no wonder it comes up as corrupt, but what I can't figure out is why this happens to only some files. It also seems to truncate the end of the file, I assume because it has been given a specific file size and it cuts off once it reaches that.

    I tested all the files I have up on the site, and two of them will not work. It isn't dependent on file size, as the two that won't work are scatter throughout the range of file sizes I have.

    Here is my download script:
    PHP Code:
    function downloader($file_path$file_name) {
        
    $ext substr(strrchr($file_name'.'), 1);
        if (
    $ext == '.zip') {
            
    $content_type "application/zip";
        } elseif (
    $ext == '.pdf') {
            
    $content_type "application/pdf";
        } elseif (
    $ext == '.ppt') {
            
    $content_type "application/vnd.ms-powerpoint";
        } elseif (
    $ext == '.doc') {
            
    $content_type "application/msword";
        } else {
            
    $content_type "application/octet-stream";
        }
        if (
    filesize("$file_path" "$file_name") <= 419430400) {
            
    header("Content-Description: File Transfer");
            
    header("Content-Type: " $content_type);
            
    header("Content-Disposition: attachment; filename=\"" basename($file_name) . "\"");
            
    header("Content-Transfer-Encoding: binary");
            
    header("Expires: 0");
            
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            
    header("Pragma: public");
            
    header("Content-Length: " filesize("$file_path" "$file_name"));
            
    ob_clean();
            
    flush();
            @
    readfile("$file_path" "$file_name");
            exit();
        } 

    The downloads are initiated by a simple form submission that passes variables to this:
    PHP Code:
    if (isset($_GET['filedl'])) {
        if (isset(
    $_POST['type']) && isset($_POST['file_name'])) {
            
    $type $_POST['type'];
            
    $file_name $_POST['file_name'];
            
    $file_path "./admin/Files/" "{$active_prod[$mdl]['txt_id']}/" "$type/";
            if (
    is_file($file_path $file_name)){
                
    downloader($file_path$file_name);
            } else {
                
    $dlfail "The file you are attempting to download does not exist.";
            }
        }

    Hopefully someone can help me out... Thanks in advance!

    EDIT: I just checked my error_log, and it seems that this error is occurring on all the downloads, but it is only these two files that are getting the output messed up by it. Am I using the ob_clean() incorrectly? If I comment it out, it works no problems, but will I have issues if I am downloading larger files, say 300 MB? Because I will be downloading large zip files with this as well...
    Last edited by Gremlyn1; 10-12-2009 at 07:33 PM.

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    check how much space is free on the server. I'm guessing but I think you don't have enought disk space.

    best regards

  • #3
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    First, sounds like you've got a buffer issue according to that warning. Second, I'd strongly recommend disabling any error output in the download script by adding this to the top of the php file...

    PHP Code:
    error_reporting(0);
    ini_set("display_errors",0); 

  • #4
    New Coder
    Join Date
    Apr 2009
    Location
    San Diego, CA
    Posts
    64
    Thanks
    2
    Thanked 1 Time in 1 Post
    Quote Originally Posted by oesxyl View Post
    check how much space is free on the server. I'm guessing but I think you don't have enought disk space.

    best regards
    These PDFs are less than 1 MB each, and they do download just fine, except those two. As I said, when I remove the ob_clean() they download with no errors at all.

    Quote Originally Posted by bcarl314 View Post
    First, sounds like you've got a buffer issue according to that warning. Second, I'd strongly recommend disabling any error output in the download script by adding this to the top of the php file...

    PHP Code:
    error_reporting(0);
    ini_set("display_errors",0); 
    I thought doing the @readfile would be enough, but I guess it doesn't catch errors on the previous functions. Any idea what the buffer error could be? It seems to be specifically related to the ob_clean.

  • #5
    New Coder
    Join Date
    Apr 2009
    Location
    San Diego, CA
    Posts
    64
    Thanks
    2
    Thanked 1 Time in 1 Post
    No other ideas on the buffer error cause?

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Gremlyn1 View Post
    These PDFs are less than 1 MB each, and they do download just fine, except those two. As I said, when I remove the ob_clean() they download with no errors at all.
    if you have 10M space on the server and 11 files of 1M you are over quota.

    Quote Originally Posted by Gremlyn1 View Post
    No other ideas on the buffer error cause?
    did you check disk space?

    best regards

  • #7
    New Coder
    Join Date
    Apr 2009
    Location
    San Diego, CA
    Posts
    64
    Thanks
    2
    Thanked 1 Time in 1 Post
    Quote Originally Posted by oesxyl View Post
    if you have 10M space on the server and 11 files of 1M you are over quota.


    did you check disk space?

    best regards
    I assume you mean memory, not disk space? The files actually download, even 300 MB file downloads work, so I don't that is my issue. If I remove the ob_clean() function from the download script, I no longer get the error and the downloads seem to work perfectly. It's just weird I would get an error on the function when so many [seemingly] use it just like I did.

    If you do mean actual disk space, we're using something like 5% of our disk space right now.


  •  

    Posting Permissions

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