...

View Full Version : Download corrupts some PDFs



Gremlyn1
10-12-2009, 07:24 PM
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:

<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:

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:

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...

oesxyl
10-12-2009, 09:40 PM
check how much space is free on the server. I'm guessing but I think you don't have enought disk space.

best regards

bcarl314
10-12-2009, 09:51 PM
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...



error_reporting(0);
ini_set("display_errors",0);

Gremlyn1
10-12-2009, 09:58 PM
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.


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...



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.

Gremlyn1
10-13-2009, 06:04 PM
No other ideas on the buffer error cause?

oesxyl
10-13-2009, 06:25 PM
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.


No other ideas on the buffer error cause?
did you check disk space?

best regards

Gremlyn1
10-13-2009, 08:29 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum