Код | session_start(); if( !isUserLoggedIn() ){ header("Location: blank.php"); exit; }
function downloadFile($path, $name, $mime){ if ($fd = fopen ($path, "r")){ $disposition = "attachment"; // "inline" to view file in browser or "attachment" to download to hard disk //$mime = "image/jpeg"; // or whatever the mime type is //$name = "foo.jpg"; // file name //$path = "/path/to/foo.jpg"; // full path and file name
if (isset($_SERVER["HTTPS"])) { /** * We need to set the following headers to make downloads work using IE in HTTPS mode. */ header("Pragma: "); header("Cache-Control: "); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 header("Cache-Control: post-check=0, pre-check=0", false); } else if ($disposition == "attachment") { header("Cache-control: private"); } else { header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); } header("Content-Type: $mime"); header("Content-Disposition:$disposition; filename=\"".trim(htmlentities($name))."\""); header("Content-Description: ".trim(htmlentities($name))); header("Content-Length: ".(string)(filesize($path))); //header("Connection: close"); while(!feof($fd)) { $buffer = fread($fd, 2048); print $buffer; } fclose ($fd); unlink($path); rmdir(dirname($path)); } }
|
Код | function isUserLoggedIn() {
if( isset( $_SESSION["user"] ) ) { return true; } return false;
}
|
Работаеть в PHP 4.3 |