Php file download_file ($ filename) {belowtoprovidethedownloadif (file_exists ($ filename) {php file download error
Write a program for downloading files.
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); return true; }else{ echo("the file not exist"); return false; } //above to provide the download }
But there is no download function. The file has been generated in the previous step. However, if I change "return true" to "exit", the download function can be implemented. However, after downloading an object, I need to perform other functions. Ask the gods what is going on? The download example on the Internet does not mean that exit is required.
------ Solution --------------------
Check where you are calling this function and where you are calling it. is there a problem?
------ Solution --------------------
In this case:
PHP code
If (download_file ($ filename) {# the following operations} else {# error prompt}
------ Solution --------------------
Discussion
Write the PHP code of an object download program.
Function download_file ($ filename ){
// Below to provide the download
If (file_exists ($ filename )){
$ File ......
------ Solution --------------------
Discussion
Reference:
In this case:
PHP code
If (download_file ($ filename )){
# The following operations
} Else {
# Error message
}
I don't quite understand what you said. did you omit the return statement? Return is omitted and cannot be run.
------ Solution --------------------
Your function return false is equivalent to preventDefault and does not submit a form.
When the answer is met, for example, if the check field is not empty and then return true, the page will jump and your action will be called.
This is a common method for form submission to prevent abnormal submission.