Thanks. I've written the following code and it works fine. I got a question on php readfile function. Will it crash or freeze or take lots of cpu usages or memory if it reads 800MB mpeg file? What are the difference between simply embeding video in a html and embeding using protection in regards to speed,memory etc.
<?php
echo"<embed src=\"protect.php?file=test.mpg\"
pluginspage=\"http://quicktime.apple.com/\"
width=160 height=150
loop=\"false\" controller=\"true\" autoplay=\"true\"
alt=\"filename.mpeg You need quicktime plug in for this to work\">
</embed>";
?>
<!-- simple html code, no protection-->
<embed src="D:\webserver\Apache\\test.mpg"
pluginspage="http://quicktime.apple.com/"
width=160 height=150
loop="false" controller="true" autoplay="false"
alt="filename.mpeg You need quicktime plug in for this to work">
</embed>
<?php
require_once("mainfile.php");
$path="D:\webserver\Apache\\";
$protect = new Protect($_GET["file"],$path);
if(is_admin()){
$protect->showfile();
}else{
echo"Please login";
}
class Protect{
var $file;
var $path;
function Protect($file,$path){
$this->file=$file;
$this->path=$path;
}
function checkFile(){
if(!empty($this->file) && !eregi("http://",$this->file) && $this->getmimetype($this->file)){
if(file_exists($this->path.$this->file) && is_readable($this->path.$this->file)){
return true;
}else{
return false;
}
}else{
return false;
}
}
function showfile(){
if($this->checkFile()){
header('Content-type: '.$this->getmimetype());
header('Content-transfer-encoding: binary');
header('Content-length: '.filesize($this->path.$this->file));
readfile($this->path.$this->file);
}
}
function downloadfile(){
if($this->checkFile()){
header('Content-Description: File Transfer');
header('Content-type: '.$this->getmimetype());
header('Content-transfer-encoding: binary');
header('Content-length: '.filesize($this->path.$this->file));
header('Content-Disposition: attachment; filename=' . basename($this->path.$this->file));
readfile($this->path.$this->file);
}
}
function getmimetype(){
$file=explode(".",$this->file);
switch($file[1]){
case"jpe":
case"jpg":
return "image/jpeg";
break;
case"mpg":
return "video/mpeg mpeg mpg mpe";
break;
case"ppt":
return "application/vnd.ms-powerpoint ppt";
break;
case"zip":
return "application/zip zip";
break;
case"gif":
return "image/gif gif";
break;
case".doc":
return "application/msword doc";
break;
case"xls":
return "application/vnd.ms-excel";
break;
case"pdf":
return "application/pdf";
break;
case"png":
return "image/png";
break;
case"exe":
return "application/octet-stream";
break;
}
}
}
?>