ถามเซียน php หน่อยค่ะ

เริ่มโดย cyberbangkok, 15 กรกฎาคม 2009, 22:19:08

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

cyberbangkok

มันเป็น script สำหรับดาวน์โหลดค่ะ แต่ไม่รู้เอาไปใช้งานยังไง

คืออยากรู้ว่ารูปแบบของลิงค์สำหรับดาวน์โหลดมันเป็นยังไง
เคยเจอสคริปอื่นเป็นแบบนี้
ตัวอย่าง

http://www.sample.com/download.php?file=sample.zip


ขอบพระคุณอย่างสูงล่วงหน้าสำหรับคำแนะนำค่ะ


<?php

/**********************************************************************
**
** A class to download files
** Version 1.0
** Features :
**      - hide the real path to the file
**      - allow / disallow download resuming
**      - partial download (useful for download managers)
**      - rename the file on the fly
**      - limit download speed
**
** Author: Mourad Boufarguine / EPT <[email protected]>
**
** License: Public Domain
** Warranty: None
**
***********************************************************************/

class Bf_Download{
   
   // just one array to gather all the properties of a download
   private $properties = array("path" => "",       // the real path to the file
                               "name" => "",       // to rename the file on the fly
                               "extension" => "",  // extension of the file
                               "type" => "",       // the type of the file
                               "size" => "",       // the file size
                               "resume" => "",     // allow / disallow resuming
                               "max_speed" => ""   // speed limit (ko) ( 0 = no limit)
                               );          

   // the constructor
   public function __construct($path, $name="", $resume="off", $max_speed=0){  // by default, resuming is NOT allowed and there is no speed limit
       $name = ($name == "") ? substr(strrchr("/".$path,"/"),1) : $name; // if "name" is not specified, th file won't be renamed
       $file_extension = strtolower(substr(strrchr($path,"."),1));       // the file extension
       switch( $file_extension ) {                                       // the file type
           case "mp3": $content_type="audio/mpeg"; break;
           case "mpg": $content_type="video/mpeg"; break;
           case "avi": $content_type="video/x-msvideo"; break;
           case "wmv": $content_type="video/x-ms-wmv";break;
           case "wma": $content_type="audio/x-ms-wma";break;
           default: $content_type="application/force-download";
       }
       $file_size = filesize($path);                                     // the file size
       $this->properties =  array(
                                   "path" => $path,
                                   "name" => $name,
                                   "extension" =>$file_extension,
                                   "type"=>$content_type,
                                   "size" => $file_size,
                                   "resume" => $resume,
                                   "max_speed" => $max_speed
                                   );
   }
   
   // public function to get the value of a property
   public function get_property ($property){
       if ( array_key_exists($property,$this->properties) )   // check if the property do exist
           return $this->properties[$property];               // get its value
       else
           return null;                                       // else return null
   }
   
   // public function to set the value of a property        
   public function set_property ($property, $value){
       if ( array_key_exists($property, $this->properties) ){ // check if the property do exist
           $this->properties[$property] = $value;             // set the new value
           return true;
       } else
           return false;
   }
   
   // public function to start the download
   public function download_file(){
       if ( $this->properties['path'] == "" )                 // if the path is unset, then error !
           echo "Nothing to download!";
       else {
           // if resuming is allowed ...
           if ($this->properties["resume"] == "on") {
               if(isset($_SERVER['HTTP_RANGE'])) {            // check if http_range is sent by browser (or download manager)
                   list($a, $range)=explode("=",$_SERVER['HTTP_RANGE']);  
                   ereg("([0-9]+)-([0-9]*)/?([0-9]*)",$range,$range_parts); // parsing Range header
                   $byte_from = $range_parts [1];     // the download range : from $byte_from ...
                   $byte_to = $range_parts [2];       // ... to $byte_to
               } else
                   if(isset($_ENV['HTTP_RANGE'])) {       // some web servers do use the $_ENV['HTTP_RANGE'] instead
                       list($a, $range)=explode("=",$_ENV['HTTP_RANGE']);
                       ereg("([0-9]+)-([0-9]*)/?([0-9]*)",$range,$range_parts); // parsing Range header
                       $byte_from = $range_parts [1];     // the download range : from $byte_from ...
                       $byte_to = $range_parts [2];       // ... to $byte_to
                   }else{
                       $byte_from = 0;                         // if no range header is found, download the whole file from byte 0 ...
                       $byte_to = $this->properties["size"] - 1;   // ... to the last byte
                   }
               if ($byte_to == "")                             // if the end byte is not specified, ...
                   $byte_to = $this->properties["size"] -1;    // ... set it to the last byte of the file
               header("HTTP/1.1 206 Patial Content");          // send the partial content header
           // ... else, download the whole file
         } else {
               $byte_from = 0;
               $byte_to = $this->properties["size"] - 1;
           }
           
           $download_range = $byte_from."-".$byte_to."/".$this->properties["size"]; // the download range
           $download_size = $byte_to - $byte_from;                                  // the download length
           
           // download speed limitation
           if (($speed = $this->properties["max_speed"]) > 0)                       // determine the max speed allowed ...
               $sleep_time = (8 / $speed) * 1e6;                                    // ... if "max_speed" = 0 then no limit (default)
           else
               $sleep_time = 0;
           
           // send the headers    
           header("Pragma: public");                                                // purge the browser cache
           header("Expires: 0");                                                    // ...
           header("Cache-Control:");                                                // ...
           header("Cache-Control: public");                                         // ...
           header("Content-Description: File Transfer");                            //  
           header("Content-Type: ".$this->properties["type"]);                     // file type
           header('Content-Disposition: attachment; filename="'.$this->properties["name"].'";');
           header("Content-Transfer-Encoding: binary");                             // transfer method
           header("Content-Range: $download_range");                                // download range
           header("Content-Length: $download_size");                                // download length
           
           // send the file content        
           $fp=fopen($this->properties["path"],"r");       // open the file
           fseek($fp,$byte_from);                          // seek to start of missing part  
           while(!feof($fp)){                              // start buffered download  
               set_time_limit(0);                           // reset time limit for big files (has no effect if php is executed in safe mode)
               print(fread($fp,1024*8));                   // send 8ko
               flush();
               usleep($sleep_time);                        // sleep (for speed limitation)
           }
           fclose($fp);                                    // close the file
           exit;  
       }
   }
}
?>

และข้างล่างนี้เป็นตัวอย่างที่เขาอธิบายมา
ยิ่งดูยิ่งงง...

<?php    
include("class.Bf_Download.php");       // load the class file

$fichier = new Bf_Download("example.zip");                          // use the original file name, disallow resuming, no speed limit                  
/*
$fichier = new Bf_Download("example.zip","My Example.zip") ;        // rename the file, disallow resuming, no speed limit
$fichier = new Bf_Download("example.zip","My Example.zip","on") ;   // rename the file, allow resuming, no speed limit
$fichier = new Bf_Download("example.zip","My Example.zip","on",80) ;   // rename the file, allow resuming, speed limit 80ko/s
*/
$fichier->download_file();

?>


thenetxx

เอ่อ ไม่ใช่เซียนครับ

สคริปที่คุณโพสมา เป็น class ครับซึ่งเขียนด้วย  php5
หลักการของ class ก็คือการเขียนแบบ oop แต่ถึงอย่างไร ก็เขียนแบบธรรมดาได้เหมือนกัน


<?
require_once('Bf_Download.php'); // เรียกไฟล์ class มาใช้ ผมไม่รู้ว่าชื่อไฟล์ว่าอะไร

$dlObj = new Bf_Download();  // ประกาศคลาส แบบไม่ใช้ constructor
$dlObj->set_property('path','c:\'); //ทำการ set path ของไฟล์
$dlObj->set_property('......','.......'); // set ค่าอื่น ๆ ตามต้องการ ดูที่ $this->properties จะมี name, extension ,type ตาม code
$dlObj->download_file(); // เมื่อ set ค่าครบแล้ว ก็ดาวน์โหลดไฟล์

?>



ตอนประกาศ class อาจะเรียก contruct ได้เลย
เปลี่ยนแค่ ระบุค่าลงไปเลย

$dlObj = new Bf_Download($path, $name="", $resume="off", $max_speed=0);



ส่วน domain คุณจะใช้แบบไหนก็ได้ครับที่สามารถนำค่ามาระบุ ไฟล์ ได้
Develop site but can't develop life
ASIA

cyberbangkok

#2
ขอบพระคุณอย่างสูงที่ตอบคะ
คือดิฉันแทบไม่รู้เรื่อง php เลย

ตามไฟลล์ที่ให้มา
อยากรู้ว่า domain สำหรับดาวน์โหลดเป็นแบบไหนคะ

ที่โหลดมามี 2 ไฟลล์คะ

ชื่อ class.Bf_Download.php

code ดังนี้คะ

<?php

/**********************************************************************
**
** A class to download files
** Version 1.0
** Features :
**      - hide the real path to the file
**      - allow / disallow download resuming
**      - partial download (useful for download managers)
**      - rename the file on the fly
**      - limit download speed
**
** Author: Mourad Boufarguine / EPT <[email protected]>
**
** License: Public Domain
** Warranty: None
**
***********************************************************************/

class Bf_Download{
   
   // just one array to gather all the properties of a download
   private $properties = array("path" => "",       // the real path to the file
                               "name" => "",       // to rename the file on the fly
                               "extension" => "",  // extension of the file
                               "type" => "",       // the type of the file
                               "size" => "",       // the file size
                               "resume" => "",     // allow / disallow resuming
                               "max_speed" => ""   // speed limit (ko) ( 0 = no limit)
                               );          

   // the constructor
   public function __construct($path, $name="", $resume="off", $max_speed=0){  // by default, resuming is NOT allowed and there is no speed limit
       $name = ($name == "") ? substr(strrchr("/".$path,"/"),1) : $name; // if "name" is not specified, th file won't be renamed
       $file_extension = strtolower(substr(strrchr($path,"."),1));       // the file extension
       switch( $file_extension ) {                                       // the file type
           case "mp3": $content_type="audio/mpeg"; break;
           case "mpg": $content_type="video/mpeg"; break;
           case "avi": $content_type="video/x-msvideo"; break;
           case "wmv": $content_type="video/x-ms-wmv";break;
           case "wma": $content_type="audio/x-ms-wma";break;
           default: $content_type="application/force-download";
       }
       $file_size = filesize($path);                                     // the file size
       $this->properties =  array(
                                   "path" => $path,
                                   "name" => $name,
                                   "extension" =>$file_extension,
                                   "type"=>$content_type,
                                   "size" => $file_size,
                                   "resume" => $resume,
                                   "max_speed" => $max_speed
                                   );
   }
   
   // public function to get the value of a property
   public function get_property ($property){
       if ( array_key_exists($property,$this->properties) )   // check if the property do exist
           return $this->properties[$property];               // get its value
       else
           return null;                                       // else return null
   }
   
   // public function to set the value of a property        
   public function set_property ($property, $value){
       if ( array_key_exists($property, $this->properties) ){ // check if the property do exist
           $this->properties[$property] = $value;             // set the new value
           return true;
       } else
           return false;
   }
   
   // public function to start the download
   public function download_file(){
       if ( $this->properties['path'] == "" )                 // if the path is unset, then error !
           echo "Nothing to download!";
       else {
           // if resuming is allowed ...
           if ($this->properties["resume"] == "on") {
               if(isset($_SERVER['HTTP_RANGE'])) {            // check if http_range is sent by browser (or download manager)
                   list($a, $range)=explode("=",$_SERVER['HTTP_RANGE']);  
                   ereg("([0-9]+)-([0-9]*)/?([0-9]*)",$range,$range_parts); // parsing Range header
                   $byte_from = $range_parts [1];     // the download range : from $byte_from ...
                   $byte_to = $range_parts [2];       // ... to $byte_to
               } else
                   if(isset($_ENV['HTTP_RANGE'])) {       // some web servers do use the $_ENV['HTTP_RANGE'] instead
                       list($a, $range)=explode("=",$_ENV['HTTP_RANGE']);
                       ereg("([0-9]+)-([0-9]*)/?([0-9]*)",$range,$range_parts); // parsing Range header
                       $byte_from = $range_parts [1];     // the download range : from $byte_from ...
                       $byte_to = $range_parts [2];       // ... to $byte_to
                   }else{
                       $byte_from = 0;                         // if no range header is found, download the whole file from byte 0 ...
                       $byte_to = $this->properties["size"] - 1;   // ... to the last byte
                   }
               if ($byte_to == "")                             // if the end byte is not specified, ...
                   $byte_to = $this->properties["size"] -1;    // ... set it to the last byte of the file
               header("HTTP/1.1 206 Patial Content");          // send the partial content header
           // ... else, download the whole file
         } else {
               $byte_from = 0;
               $byte_to = $this->properties["size"] - 1;
           }
           
           $download_range = $byte_from."-".$byte_to."/".$this->properties["size"]; // the download range
           $download_size = $byte_to - $byte_from;                                  // the download length
           
           // download speed limitation
           if (($speed = $this->properties["max_speed"]) > 0)                       // determine the max speed allowed ...
               $sleep_time = (8 / $speed) * 1e6;                                    // ... if "max_speed" = 0 then no limit (default)
           else
               $sleep_time = 0;
           
           // send the headers    
           header("Pragma: public");                                                // purge the browser cache
           header("Expires: 0");                                                    // ...
           header("Cache-Control:");                                                // ...
           header("Cache-Control: public");                                         // ...
           header("Content-Description: File Transfer");                            //  
           header("Content-Type: ".$this->properties["type"]);                     // file type
           header('Content-Disposition: attachment; filename="'.$this->properties["name"].'";');
           header("Content-Transfer-Encoding: binary");                             // transfer method
           header("Content-Range: $download_range");                                // download range
           header("Content-Length: $download_size");                                // download length
           
           // send the file content        
           $fp=fopen($this->properties["path"],"r");       // open the file
           fseek($fp,$byte_from);                          // seek to start of missing part  
           while(!feof($fp)){                              // start buffered download  
               set_time_limit(0);                           // reset time limit for big files (has no effect if php is executed in safe mode)
               print(fread($fp,1024*8));                   // send 8ko
               flush();
               usleep($sleep_time);                        // sleep (for speed limitation)
           }
           fclose($fp);                                    // close the file
           exit;  
       }
   }
}
?>

และไฟลล์ที่ 2 ชื่อ example.php เป็นตัวอย่างการใช้มั่งคะ ไม่แน่ใจ

code ตามนี้

<?php   
include("class.Bf_Download.php");       // load the class file

$fichier = new Bf_Download("example.zip");                          // use the original file name, disallow resuming, no speed limit                 
/*
$fichier = new Bf_Download("example.zip","My Example.zip") ;        // rename the file, disallow resuming, no speed limit
$fichier = new Bf_Download("example.zip","My Example.zip","on") ;   // rename the file, allow resuming, no speed limit
$fichier = new Bf_Download("example.zip","My Example.zip","on",80) ;   // rename the file, allow resuming, speed limit 80ko/s
*/
$fichier->download_file();

?>

รบกวนเขียน domain ให้ดูหน่อยได้มั้ยคะ


:-[



thenetxx

ใช้ ตาม example ก็ได้ครับ


เปลี่ยนชื่อเป็น dl.php
เวลาเรียก dl.php?file=xxx.zip


<?php    
include("class.Bf_Download.php");       // load the class file

$file $_GET['file'];
$patch 'home\yourname\'.$file;
$fichier = new Bf_Download($patch,"My Example.zip","on",80) ;   // rename the file, allow resuming, speed limit 80ko/s
$fichier->download_file();

// การ set ค่า
// ($patch,"My Example.zip","on",80)   << ช่องแรก พาธไฟล์, ช่องสองถ้าต้องการเปลี่ยนชื่อ , ถ้าเปิดให้ดาวน์โหลดแบบ resume กลับมาโหลดต่อจากเดิมได้ , และสุดท้าย 80 คือความเร็วในการดาวน์โหลดไฟล์ แล้วแต่ระบุครับ

?>




PS. ถ้าไม่มีความรู้ด้านการเขียนโปรแกรมเลย การใช้คลาส ถือว่าเกินตัวไปหน่อยครับ ^___^

Develop site but can't develop life
ASIA

ayeweb


[direct=https://www.bitimer.in.th/]ข่าวไอที[/direct] ข่าวสารไอที แอพไอโฟน บริการอื่นๆ
[direct=https://page.line.me/gnm7628z]บริการ ตรวจหวย[/direct] อื่นๆ ทั่วไปสาระน่ารู้ ความรู้ต่างๆ
[direct=https://goo.gl/XQp91t]Host ไทย[/direct] เว็บผู้หญิงนะคะ แต่ผู้ชายก็เข้าได้ค่ะ
[direct=https://page.line.me/oer1981h]ตรวจหวย[/direct]
ตรวจหวย ผลสลากกินแบ่งรัฐบาล>>
[direct=https://goo.gl/H3JCzK]เช่าโฮสติ้ง Ruk-com[/direct]

cyberbangkok

#5
 ;)
ขอขอบคุณอีกครั้งนะคะที่อุตส่าห์ตอบ


คือดิฉันไม่รู้เรื่อง php เลย แต่ต้องการใช้งานสคริปทำนองนี้ที่มี** Features : หลักๆ
ดังนี้คะ
**      - hide the real path to the file
**      - allow / disallow download resuming
**      - partial download (useful for download managers)
**      - limit download speed

เลยลองค้นหาที่Googleเลยได้สคริปนี้มา ซึ่งดูแล้วมีฟังชั่นครบตามต้องการ
คุณพอจะรู้จักสคริปทำนองนี้อีกมั้ยที่มี Features : ด้านบน
พอจะแนะนำได้มั้ยคะ จะลองใช้ดูหลายๆอัน

ขอแค่วิธีใช้งานคร่าวๆก็พอคะ เพราะดิฉันแก้ไขดัดแปลงอะไรไม่เป็นเลยคะ

untilate


cyberbangkok

ขอบคุณคะ
ลองดูแล้ว ไม่เจอ

thenetxx

อ้างถึงจาก: cyberbangkok ใน 16 กรกฎาคม 2009, 17:40:12
ขอบคุณคะ
ลองดูแล้ว ไม่เจอ

เอ่อ ผมคลิกไปดูแล้ว ก็เพียบเลยอ่า

ส่วนที่แนะนำไปด้านบน

เปลี่ยนชื่อเป็น dl.php
เวลาเรียก dl.php?file=xxx.zip
Develop site but can't develop life
ASIA

cyberbangkok

#9
ลองแล้วคะ

url
http://127.0.0.1/dl.php?file=xxx.rar

ไฟล์ xxx.rar อยู่ที่ www folder เดียวกับสคริป

มันเป็นแบบนี้คะ

ลองที่เครื่องตัวเอง ใช้ EasyPHP Server

Parse error: parse error, unexpected $end in E:\AAA\www\dl.php on line 12

<?php    
include("class.Bf_Download.php");       // load the class file

$file $_GET['file'];
$patch 'E:\AAA\www\'.$file;
$fichier = new Bf_Download($patch,"My Example.zip","on",80) ;   // rename the file, allow resuming, speed limit 80ko/s
$fichier->download_file();

// การ set ค่า
// ($patch,"My Example.zip","on",80)   << ช่องแรก พาธไฟล์, ช่องสองถ้าต้องการเปลี่ยนชื่อ , ถ้าเปิดให้ดาวน์โหลดแบบ resume กลับมาโหลดต่อจากเดิมได้ , และสุดท้าย 80 คือความเร็วในการดาวน์โหลดไฟล์ แล้วแต่ระบุครับ

?>


thenetxx

หาไลน์ 12 ไม่เจอ น่าจะตรง comment

ลบ คอมเม้นออกสิครับ  ^__^
Develop site but can't develop life
ASIA

awat

เทพ ๆ พากันมาตอบให้แล้ว 


มาหาความรู้
.NET Developer, Cloud computing Developer
รับทำ component joomla, wordpress, drupal

cyberbangkok

<?php    
include("class.Bf_Download.php");       // load the class file

$file $_GET['file'];
$patch 'www\'.$file;
$fichier = new Bf_Download($patch,"My Example.zip","on",80) ;   // rename the file, allow resuming, speed limit 80ko/s
$fichier->download_file();

?>


ลบแล้วคะ
แต่ก็ยังไม่ได้

Parse error: parse error, unexpected $end in E:\AAA\www\dl.php on line 9


line ที่ว่า
มันคือตัวนี้คะ

?>

thenetxx

เวนกำ เล่นซะไปไม่เป็นเลย

ผมสงสัยว่าในไฟล์มันมี ?> กี่ตัวครับ
Develop site but can't develop life
ASIA

cyberbangkok

ตามนี้เลยคะ

<?php    
include("class.Bf_Download.php");

$file $_GET['file'];
$patch 'www\'.$file;
$fichier = new Bf_Download($patch,"My Example.zip","on",80) ;
$fichier->download_file();

?>

Normaderm

#15
ลองลบคอมเม้นออกหมมดเลยดิครับ
<?php    
include("class.Bf_Download.php");    // load the class file

$file = $_GET['file'];
$patch = 'www\'.$file;
$fichier = new Bf_Download($patch,"My Example.zip","on",80) ;   // rename the file, allow resuming, speed limit 80ko/s
$fichier->download_file();

?>

[direct=https://www.facebook.com/aiunlockedvip]สอน AI[/direct]| [direct=https://aiunlock.co/]คอร์ส AI[/direct] | [direct=https://aiunlock.co/]สอน n8n[/direct]  | [direct=https://www.aiunlockinnovations.com/]สอน AI เชียงใหม่[/direct]

alert

คนตอบเยอะละ เข้ามาดูอย่างเดียวละกันครับ  :)
***** รับซื้อเว็บไซต์สายขาวคุณภาพ  ตั้งแต่ 500-30,000 uip มี traffic มาจาก Google  และไม่เคยโดนแบน adsense  เสนอราคามาทาง pm ได้เลยครับ *****

cyberbangkok

<?php    
include("class.Bf_Download.php");

$file $_GET['file'];
$patch 'www\'.$file;
$fichier = new Bf_Download($patch,"My Example.zip","on",80);
$fichier->download_file();

?>


ลองแล้วเหมือนเดิมคะ

Normaderm

หุหุ สงสัยจะไปเออเร้อ ใน คลาส Bf_Download ละมั้ง... โค้ดยาวเหยียดเลย เห็นแล้ว สยอง  :P
[direct=https://www.facebook.com/aiunlockedvip]สอน AI[/direct]| [direct=https://aiunlock.co/]คอร์ส AI[/direct] | [direct=https://aiunlock.co/]สอน n8n[/direct]  | [direct=https://www.aiunlockinnovations.com/]สอน AI เชียงใหม่[/direct]

cyberbangkok

ไฟล์ class.Bf_Download.php คะ

<?php

/**********************************************************************
**
** A class to download files
** Version 1.0
** Features : 
**      - hide the real path to the file
**      - allow / disallow download resuming
**      - partial download (useful for download managers)
**      - rename the file on the fly
**      - limit download speed
**
** Author: Mourad Boufarguine / EPT <[email protected]>
**
** License: Public Domain
** Warranty: None
**
***********************************************************************/

class Bf_Download{
    
    
// just one array to gather all the properties of a download
    
private $properties = array("path" => "",       // the real path to the file 
                                
"name" => "",       // to rename the file on the fly
                                
"extension" => "",  // extension of the file
                                
"type" => "",       // the type of the file
                                
"size" => "",       // the file size
                                
"resume" => "",     // allow / disallow resuming
                                
"max_speed" => ""   // speed limit (ko) ( 0 = no limit)
                                
);          

    
// the constructor
    
public function __construct($path$name=""$resume="off"$max_speed=0){  // by default, resuming is NOT allowed and there is no speed limit
        
$name = ($name == "") ? substr(strrchr("/".$path,"/"),1) : $name// if "name" is not specified, th file won't be renamed
        
$file_extension strtolower(substr(strrchr($path,"."),1));       // the file extension
        
switch( $file_extension ) {                                       // the file type
            
case "mp3"$content_type="audio/mpeg"; break;
            case 
"mpg"$content_type="video/mpeg"; break;
            case 
"avi"$content_type="video/x-msvideo"; break;
            case 
"wmv"$content_type="video/x-ms-wmv";break;
            case 
"wma"$content_type="audio/x-ms-wma";break; 
            default: 
$content_type="application/force-download";
        }
        
$file_size filesize($path);                                     // the file size
        
$this->properties =  array(
                                    
"path" => $path
                                    
"name" => $name
                                    
"extension" =>$file_extension,
                                    
"type"=>$content_type
                                    
"size" => $file_size
                                    
"resume" => $resume
                                    
"max_speed" => $max_speed
                                    
);
    }
    
    
// public function to get the value of a property
    
public function get_property ($property){
        if ( 
array_key_exists($property,$this->properties) )   // check if the property do exist
            
return $this->properties[$property];               // get its value
        
else
            return 
null;                                       // else return null
    
}
    
    
// public function to set the value of a property        
    
public function set_property ($property$value){
        if ( 
array_key_exists($property$this->properties) ){ // check if the property do exist
            
$this->properties[$property] = $value;             // set the new value
            
return true;
        } else
            return 
false;
    }
    
    
// public function to start the download
    
public function download_file(){
        if ( 
$this->properties['path'] == "" )                 // if the path is unset, then error !
            
echo "Nothing to download!";
        else {
            
// if resuming is allowed ...
            
if ($this->properties["resume"] == "on") {
                if(isset(
$_SERVER['HTTP_RANGE'])) {            // check if http_range is sent by browser (or download manager)
                    
list($a$range)=explode("=",$_SERVER['HTTP_RANGE']);  
                    
ereg("([0-9]+)-([0-9]*)/?([0-9]*)",$range,$range_parts); // parsing Range header
                    
$byte_from $range_parts [1];     // the download range : from $byte_from ...
                    
$byte_to $range_parts [2];       // ... to $byte_to 
                
} else
                    if(isset(
$_ENV['HTTP_RANGE'])) {       // some web servers do use the $_ENV['HTTP_RANGE'] instead
                        
list($a$range)=explode("=",$_ENV['HTTP_RANGE']);
                        
ereg("([0-9]+)-([0-9]*)/?([0-9]*)",$range,$range_parts); // parsing Range header
                        
$byte_from $range_parts [1];     // the download range : from $byte_from ...
                        
$byte_to $range_parts [2];       // ... to $byte_to 
                    
}else{
                        
$byte_from 0;                         // if no range header is found, download the whole file from byte 0 ...
                        
$byte_to $this->properties["size"] - 1;   // ... to the last byte
                    
}
                if (
$byte_to == "")                             // if the end byte is not specified, ...
                    
$byte_to $this->properties["size"] -1;    // ... set it to the last byte of the file
                
header("HTTP/1.1 206 Patial Content");          // send the partial content header
            // ... else, download the whole file
} else {
                
$byte_from 0;
                
$byte_to $this->properties["size"] - 1;
            }
            
            
$download_range $byte_from."-".$byte_to."/".$this->properties["size"]; // the download range
            
$download_size $byte_to $byte_from;                                  // the download length
            
            // download speed limitation
            
if (($speed $this->properties["max_speed"]) > 0)                       // determine the max speed allowed ...
                
$sleep_time = ($speed) * 1e6;                                    // ... if "max_speed" = 0 then no limit (default)
            
else
                
$sleep_time 0;
            
            
// send the headers    
            
header("Pragma: public");                                                // purge the browser cache
            
header("Expires: 0");                                                    // ...
            
header("Cache-Control:");                                                // ...
            
header("Cache-Control: public");                                         // ... 
            
header("Content-Description: File Transfer");                            //  
            
header("Content-Type: ".$this->properties["type"]);                     // file type
            
header('Content-Disposition: attachment; filename="'.$this->properties["name"].'";');
            
header("Content-Transfer-Encoding: binary");                             // transfer method
            
header("Content-Range: $download_range");                                // download range
            
header("Content-Length: $download_size");                                // download length
            
            // send the file content        
            
$fp=fopen($this->properties["path"],"r");       // open the file 
            
fseek($fp,$byte_from);                          // seek to start of missing part   
            
while(!feof($fp)){                              // start buffered download  
                
set_time_limit(0);                           // reset time limit for big files (has no effect if php is executed in safe mode)
                
print(fread($fp,1024*8));                   // send 8ko 
                
flush();
                
usleep($sleep_time);                        // sleep (for speed limitation)
            
}
            
fclose($fp);                                    // close the file
            
exit;  
        }
    }
}
?>