Zdravim,
pokud tomu dobre rozumim, tak chcete download skript, ktery predhodi prohlizeci hlavicku - tedy moznost volby - Ulozit X Otevrit. Pouzivam na to nasledujici tridu:
<?php
class DOWNLOAD {
var $filename = "";
var $path = "";
var $mimes = array("zip" => "application/zip",
"pdf" => "application/pdf",
"doc" => "application/msword",
"xls" => "application/vnd.ms-excel",
"ppt" => "application/vnd.ms-powerpoint",
"exe" => "application/octet-stream",
"gif" => "image/gif",
"png" => "image/png",
"jpg" => "image/jpeg",
"jpeg" => "image/jpeg",
"mp3" => "audio/mpeg",
"wav" => "audio/x-wav",
"mpeg" => "video/mpeg",
"mpg" => "video/mpeg",
"mpe" => "video/mpeg",
"mov" => "video/quicktime",
"avi" => "video/x-msvideo"); function DOWNLOAD($path, $filename = "") {
$this->path = $path;
$this->filename = isset($filename) ? $filename : basename($path);
} function file_extension() {
$path_info = pathinfo($this->filename);
return $path_info["extension"];
} function mime_type() {
if(array_key_exists($this->file_extension(), $this->mimes)) return $this->mimes[$this->file_extension()];
else return "application/octet-stream";
} function exists() {
if(file_exists($this->path)) return true;
return false;
} function size() {
if($this->exists()) return filesize($this->path);
return false;
} function permission() {
return substr(decoct(fileperms($this->path)), -1);
} function get_file() {
if($this->exists() && $this->permission() >= 4) {
header("Content-type: " . $this->mime_type());
header("Content-Disposition: attachment; filename=\"" . $this->filename . "\"");
header("Content-Length: " . $this->size());
$fc = readfile($this->path, "r");
return $fc;
}
return false;
}
}
?>
Pouziti je pak velmi snadne, a to:
<?php
include("./download.class.php");
$downloadfile = new DOWNLOAD("./", "foo.pdf");
if (!$downloadfile->get_file()) echo "Chyba";
?>
|