File downloading function through PHP code

Sometimes, you may need to implement download function for access control to avoid illegal connection.


Refer below reference code.

    Header("Content-type: file/unknown");
    Header("Content-Disposition: 1; filename=\"$rfile\"");
    Header("Content-Description: PHP3 Generated Data");
    Header("Pragma: no-cache");
    Header("Expires: 0");
    $agent = getenv("HTTP_USER_AGENT");
    $contents =  urldecode($contents);
    if(eregi("windows", $agent))
        $contents = eregi_replace("\n","\r\n", $contents);
    echo $contents;

Leave a Reply

Your email address will not be published. Required fields are marked *