Hi,
this code perfectly works when I try to force the download of a file,
by calling it directly.
<?php
$file = "onefilename.tx t";
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="applica tion/force-download";
header("Content-Type: $ctype");
//
$header="Conten t-Disposition: attachment; filename=".$fil ename.";";
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($t heFile){
$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="applica tion/force-download";
header("Content-Type: $ctype");
//
$header="Conten t-Disposition: attachment; filename=".$fil ename.";";
header($header );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$len);
@readfile($file );
exit;
}
After instantiating the class, I call
instance.downlo adFile("myFile. txt") but I get no prompt.
What am I doing the wrong way?
Thanks.
this code perfectly works when I try to force the download of a file,
by calling it directly.
<?php
$file = "onefilename.tx t";
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="applica tion/force-download";
header("Content-Type: $ctype");
//
$header="Conten t-Disposition: attachment; filename=".$fil ename.";";
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($t heFile){
$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="applica tion/force-download";
header("Content-Type: $ctype");
//
$header="Conten t-Disposition: attachment; filename=".$fil ename.";";
header($header );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$len);
@readfile($file );
exit;
}
After instantiating the class, I call
instance.downlo adFile("myFile. txt") but I get no prompt.
What am I doing the wrong way?
Thanks.
Comment