PHP File Download error

Source: Internet
Author: User
PHP File Download error
Wrote a file to download the program
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} 

However, there is no feature to download. The file has been generated in the previous step. But if I change the return to True to exit the download function can be implemented, but after the file download I also have to do other functions. Ask the gods, what's going on? I see the download example on the Internet is not to say that we need to exit.


------Solution--------------------
See where you call this function, check where it is called, where is there a problem?
------Solution--------------------
Here's the thing:
PHP code
if (Download_file ($filename)) {#下面的操作}else{#错误提示} 
------Solution--------------------
discussion
wrote a file download program PHP code
Function Dow Nload_file ($filename) {
//below to provide the download
if (file_exists ($filename)) {

$file ...

------Solution--------------------
discussion

Reference:

this:
PHP code

if (Download_file ($filename)) {
#下面的操作
}else{
#错误提示
}



I don't know what you're talking about. Do you want to omit the return? Return omitted I can't run

------Solution--------------------
Your function return false is equivalent to Preventdefault not submitting the form
When a reply is satisfied, such as checking that the field is non-empty and then return true; The page does not jump until it calls your action
This is the form submission common blocking exception submission method
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.