|
Posted by Duff B on 11/28/05 13:56
Hi,
this code perfectly works when I try to force the download of a file,
by calling it directly.
<?php
$file = "onefilename.txt";
if (!is_file($file)) { die("<b>404 File not found!</b>"); }
//
$filename = basename($file);
//
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
//
$ctype="application/force-download";
header("Content-Type: $ctype");
//
$header="Content-Disposition: attachment; filename=".$filename.";";
header($header );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$len);
@readfile($file);
exit;
?>
Now, I can't get this working as a method of a class:
function downloadFile($theFile){
$file = $theFile;
if (!is_file($file)) { die("<b>404 File not found!</b>"); }
//
$filename = basename($file);
//
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
//
$ctype="application/force-download";
header("Content-Type: $ctype");
//
$header="Content-Disposition: attachment; filename=".$filename.";";
header($header );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$len);
@readfile($file);
exit;
}
After instantiating the class, I call
instance.downloadFile("myFile.txt") but I get no prompt.
What am I doing the wrong way?
Thanks.
Navigation:
[Reply to this message]
|