PHP Classes

File: little_leach.php

Recommend this page to a friend!
  Classes of Andrey Nikishaev   Little Leach   little_leach.php   Download  
File: little_leach.php
Role: Class source
Content type: text/plain
Description: class
Class: Little Leach
Serve files protected from direct download
Author: By
Last change: bugfix
Date: 15 years ago
Size: 1,102 bytes
 

Contents

Class file image Download
<?php
class Leach {
    var
$pathes=array();
    public function
__construct($pathes) {
       
$this->pathes=$pathes;
    }
    public function
getFile($filename,$dir='') {
       
        if(!
$dir) {
            foreach(
$this->pathes as $k=>$v) {
                if(
file_exists($_SERVER['DOCUMENT_ROOT'].$v.$filename)) {$dir=$_SERVER['DOCUMENT_ROOT'].$v;}
            }
        } else {
           
$dir=$_SERVER['DOCUMENT_ROOT'].$this->pathes[$dir];
        }
        if(
file_exists($dir.$filename)) {
           
$_SESSION['leach']=array();
           
header("Content-type: application/other");
           
header("Content-Disposition: attachment; filename=".$filename);
           
header("Cache-Control: must-revalidate");
                       
$fp=fopen($dir.$filename,'r');
           
$contents = '';
                        while (!
feof($fp)) {
                           
$contents=fread($fp, 1024);
                            echo
$contents;
                        }
                       
fclose($fp);

        } else {
           
$_SESSION['leach']=array();
            echo
"File doesn't exists.";
        }
    }
    public function
setAccess($filename) {
       
$_SESSION['leach'][]=$filename;
        return
true;
    }
}