Return to Snippet

Revision: 29513
at July 31, 2010 02:24 by mfigge


Updated Code
if (file_exists("path/".$filename)) {
    header('Content-Description: File Transfer');
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"".filename."\"\n");
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: '.filesize("path/".$filename));
    ob_clean();
    flush();
    readfile("path/".$filename);
    exit;
}

// if readfile is blocked, try:


if (file_exists("path/".$filename)) {
    header('Content-Description: File Transfer');
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"".filename."\"\n");
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: '.filesize("path/".$filename));
    ob_clean();
    flush();
    $fp=fopen("path/".$filename, "r");
    fpassthru($fp);
    exit;
}

Revision: 29512
at July 31, 2010 02:16 by mfigge


Initial Code
if (file_exists("path/".$filename)) {
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"".filename."\"\n");
    readfile("path/".$filename);
}

// if readfile is blocked, try:


if (file_exists("path/".$filename)) {
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"".filename."\"\n");
    $fp=fopen("path/".$filename, "r");
    fpassthru($fp);
}

Initial URL

                                

Initial Description

                                

Initial Title
Force File Download

Initial Tags
file, download

Initial Language
PHP