PHPcodefunctiondownload_file ($ filename) {// belowtoprovidethedownloadif (file_exists (php file download problem
PHP code
function download_file($filename){ //below to provide the download if (file_exists($filename)) { $file = fopen($filename); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($filename)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($filename) . ' bytes'); //ob_clean(); //flush(); readfile($filename); fclose($file); exit;}$this->_redirect('xxxxxxx');
The above is a common PHP file download code on the internet. my problem is this. Do I need to click a button to download and refresh the page content? that is to say, I do not want to exit; after the file is downloaded, I need to continue executing the code. That is to say, after my download is complete, $ this-> _ redirect ('xxxxxxx'); this statement is not executed. Is there any solution?
------ Solution --------------------
$ File = fopen ($ filename );
Readfile ($ filename );
Fclose ($ file );
Just read the file directly.
This redirection can only be done with JS, but onclick can only mark the variable, and wait for the loss of focus to check the variable again.
C/C ++ code
[User: root Time: 23: 25: 51 Path:/home/apache/web] $ cat index.html