By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,118 Members | 1,134 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,118 IT Pros & Developers. It's quick & easy.

PHP scripting problem

P: n/a
I have a VERY frustrating script problem I hope some one can help me with.
I am using part of the following PHP download script to allow users to
download files from my website:

<?php
$file = '/download/whiteskullvalley.exe';
header('Content-Description: File Transfer');
header("Content-Type: application/octet-stream");
header('Content-Length: ' . filesize($filename));
header('Content-Disposition: attachment; filename=' . basename($file));
readfile($file);
?>

Everything works fine as long as the file size is relatively small (say
around 5 MB) but if I try and use it to download a large file (say around 50
MB) I get Error 500 "Internal Server Error" and when I check my error log I
get:

Premature end of script headers: /web/cgi-bin/php4

I have also tried a few different download scripts and they all give me the
same error.

Any help with this would be greatly appreciated
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
skadmin wrote:
<?php
$file = '/download/whiteskullvalley.exe';
header('Content-Description: File Transfer');
header("Content-Type: application/octet-stream");
header('Content-Length: ' . filesize($filename));
header('Content-Disposition: attachment; filename=' . basename($file));
readfile($file);
?>

Everything works fine as long as the file size is relatively small (say
around 5 MB) but if I try and use it to download a large file (say around
50 MB) I get Error 500 "Internal Server Error" and when I check my error
log I get:


http://www.php.net/manual/en/function.flush.php
http://www.php.net/manual/en/functio...time-limit.php

C.
Jul 17 '05 #2

P: n/a
In article <ksvwd.585224$D%.458796@attbi_s51>,
"skadmin" <So*******@Nowhere.com> wrote:
I have a VERY frustrating script problem I hope some one can help me with.
I am using part of the following PHP download script to allow users to
download files from my website:

<?php
$file = '/download/whiteskullvalley.exe';
header('Content-Description: File Transfer');
header("Content-Type: application/octet-stream");
header('Content-Length: ' . filesize($filename));
header('Content-Disposition: attachment; filename=' . basename($file));
readfile($file);
?>

Everything works fine as long as the file size is relatively small (say
around 5 MB) but if I try and use it to download a large file (say around 50
MB) I get Error 500 "Internal Server Error" and when I check my error log I
get:

Premature end of script headers: /web/cgi-bin/php4

I have also tried a few different download scripts and they all give me the
same error.

Any help with this would be greatly appreciated


I do the following with my code:

$h = fopen($file, "rb");
$content_len = (int) filesize($file);
$content_file = fread($h, $content_len);
fclose($h);

@ob_end_clean();
@ini_set('zlib.output_compression', 'Off');
header("Pragma: no-cache");
header("Cache-control: private");

header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: pre-check=0, post-check=0, max-age=0');
header('Content-Transfer-Encoding: none');
if (ereg("IE",$_SERVER[HTTP_USER_AGENT]))
header('Content-Type: application/octetstream; name="' . $file . '"');
else
header('Content-Type: application/octet-stream; name="' . $file . '"');

header('Content-Disposition: attachment; filename="' . $file . '"');
header("Content-length: $content_len");
echo $content_file;
exit;

--
DeeDee, don't press that button! DeeDee! NO! Dee...

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.