mitchlrm
01-05-2006, 10:50 PM
I'm trying to force the download of a wmv file. Using the following
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
$size = filesize(videodir.$filename);
// echo("size ".$size);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=\"".$filename."\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$size);readfile(videodir.$filename);
It does actually download the file but it adds about 5 bytes to the beginning of the file that makes it unusable.
Any advice on how to avoid the extra bytes???
orbitz
01-06-2006, 12:00 AM
I got this Note from: http://us3.php.net/filesize
Note: Because PHP's integer type is signed and many platforms use 32bit integers, filesize() may return unexpected results for files which are larger than 2GB. For files between 2GB and 4GB in size this can usually be overcome by using sprintf("%u", filesize($file)).
mitchlrm
01-06-2006, 12:10 AM
Thanks for the info, and it might help, but the test file I'm using is just 301k.
Any other ideas?
Take a look at line 3 please:
$size = filesize(videodir.$filename);
What is videodir? variable? then should be: $videodir
Constant? then should be: "videodir"
Wish this help
Korvan
01-06-2006, 12:18 PM
check for any whitespace at the beginning or end of your PHP file and eliminate it. Did you open the file you downloaded in a text editor to see what characters its slapping on the front of the file?
mitchlrm
01-06-2006, 01:24 PM
Oras,
videodir isn't the problem. It was defined with define("videodir","video/")
Korvan,
Thanks. That was it. I wouldn't have thought of that...the power of the forum :)
Mitch
Korvan
01-06-2006, 04:58 PM
Anytime.
And oras, to access a constant you have 2 options
1) constant("constname");
2) constname (no quotes, no $)
Source=http://us3.php.net/manual/en/language.constants.php
Constants do not have a dollar sign ($) before them;
Constants may only be defined using the define() function, not by simple assignment;
Constants may be defined and accessed anywhere without regard to variable scoping rules;
Constants may not be redefined or undefined once they have been set; and
Constants may only evaluate to scalar values.
preeee
01-06-2006, 06:12 PM
You can solve this problem, if you use ob_clear() before the first header. In this case:
ob_clear();
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=\"".$filename."\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$size);readfile(videodir.$filename);
I hope it ll help in some case.
mitchlrm
01-06-2006, 08:16 PM
I think you're referring to ob_clean(); not ob_clear(); but thanks for the suggestion.