ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ThaiSEOBoard.comพัฒนาเว็บไซต์Programmingถามเซียน php หน่อยค่ะ
หน้า: [1] 2  ทั้งหมด   ลงล่าง
พิมพ์
ผู้เขียน หัวข้อ: ถามเซียน php หน่อยค่ะ  (อ่าน 3176 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
cyberbangkok
Newbie
*

พลังน้ำใจ: 1
ออฟไลน์ ออฟไลน์

กระทู้: 10



ดูรายละเอียด
« เมื่อ: 15 กรกฎาคม 2009, 22:19:08 »

มันเป็น 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*Cool);                   // 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();

?>

« แก้ไขครั้งสุดท้าย: 15 กรกฎาคม 2009, 22:45:53 โดย cyberbangkok » บันทึกการเข้า
thenetxx
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 41
ออฟไลน์ ออฟไลน์

กระทู้: 1,979



ดูรายละเอียด เว็บไซต์
« ตอบ #1 เมื่อ: 15 กรกฎาคม 2009, 23:00:38 »

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

สคริปที่คุณโพสมา เป็น 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
Newbie
*

พลังน้ำใจ: 1
ออฟไลน์ ออฟไลน์

กระทู้: 10



ดูรายละเอียด
« ตอบ #2 เมื่อ: 15 กรกฎาคม 2009, 23:07:53 »

ขอบพระคุณอย่างสูงที่ตอบคะ
คือดิฉันแทบไม่รู้เรื่อง 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*Cool);                   // 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 ให้ดูหน่อยได้มั้ยคะ


 Embarrassed


« แก้ไขครั้งสุดท้าย: 15 กรกฎาคม 2009, 23:31:54 โดย cyberbangkok » บันทึกการเข้า
thenetxx
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 41
ออฟไลน์ ออฟไลน์

กระทู้: 1,979



ดูรายละเอียด เว็บไซต์
« ตอบ #3 เมื่อ: 16 กรกฎาคม 2009, 12:59:47 »

ใช้ ตาม 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
Verified Seller
เจ้าพ่อบอร์ดเสียว
*

พลังน้ำใจ: 321
ออฟไลน์ ออฟไลน์

กระทู้: 5,202



ดูรายละเอียด เว็บไซต์
« ตอบ #4 เมื่อ: 16 กรกฎาคม 2009, 13:18:56 »

มาเก็บความรู้
บันทึกการเข้า


ข่าวไอที ข่าวสารไอที แอพไอโฟน บริการอื่นๆ
บริการ ตรวจหวย อื่นๆ ทั่วไปสาระน่ารู้ ความรู้ต่างๆ
Host ไทย เว็บผู้หญิงนะคะ แต่ผู้ชายก็เข้าได้ค่ะ
ตรวจหวย
ตรวจหวย ผลสลากกินแบ่งรัฐบาล>>
เช่าโฮสติ้ง Ruk-com
cyberbangkok
Newbie
*

พลังน้ำใจ: 1
ออฟไลน์ ออฟไลน์

กระทู้: 10



ดูรายละเอียด
« ตอบ #5 เมื่อ: 16 กรกฎาคม 2009, 17:00:11 »

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


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

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

ขอแค่วิธีใช้งานคร่าวๆก็พอคะ เพราะดิฉันแก้ไขดัดแปลงอะไรไม่เป็นเลยคะ
« แก้ไขครั้งสุดท้าย: 16 กรกฎาคม 2009, 17:03:14 โดย cyberbangkok » บันทึกการเข้า
untilate
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 106
ออฟไลน์ ออฟไลน์

กระทู้: 2,310



ดูรายละเอียด
« ตอบ #6 เมื่อ: 16 กรกฎาคม 2009, 17:26:52 »


ลองดูครับ

http://www.tosdn.com/searchsc....9%D5%E9%21++++&opt=advance
บันทึกการเข้า
cyberbangkok
Newbie
*

พลังน้ำใจ: 1
ออฟไลน์ ออฟไลน์

กระทู้: 10



ดูรายละเอียด
« ตอบ #7 เมื่อ: 16 กรกฎาคม 2009, 17:40:12 »

ขอบคุณคะ
ลองดูแล้ว ไม่เจอ
บันทึกการเข้า
thenetxx
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 41
ออฟไลน์ ออฟไลน์

กระทู้: 1,979



ดูรายละเอียด เว็บไซต์
« ตอบ #8 เมื่อ: 16 กรกฎาคม 2009, 17:42:55 »

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

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

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

เปลี่ยนชื่อเป็น dl.php
เวลาเรียก dl.php?file=xxx.zip
บันทึกการเข้า

Develop site but can't develop life
ASIA
cyberbangkok
Newbie
*

พลังน้ำใจ: 1
ออฟไลน์ ออฟไลน์

กระทู้: 10



ดูรายละเอียด
« ตอบ #9 เมื่อ: 16 กรกฎาคม 2009, 17:54:56 »

ลองแล้วคะ

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[&#39;file&#39;];
$patch = &#39;E:\AAA\www\&#39;.$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 คือความเร็วในการดาวน์โหลดไฟล์ แล้วแต่ระบุครับ

?>
« แก้ไขครั้งสุดท้าย: 16 กรกฎาคม 2009, 17:59:56 โดย cyberbangkok » บันทึกการเข้า
thenetxx
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 41
ออฟไลน์ ออฟไลน์

กระทู้: 1,979



ดูรายละเอียด เว็บไซต์
« ตอบ #10 เมื่อ: 16 กรกฎาคม 2009, 20:15:04 »

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

ลบ คอมเม้นออกสิครับ  ^__^
บันทึกการเข้า

Develop site but can't develop life
ASIA
awat
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 46
ออฟไลน์ ออฟไลน์

กระทู้: 1,211



ดูรายละเอียด
« ตอบ #11 เมื่อ: 16 กรกฎาคม 2009, 20:47:22 »

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


มาหาความรู้
บันทึกการเข้า

.NET Developer, Cloud computing Developer
รับทำ component joomla, wordpress, drupal
cyberbangkok
Newbie
*

พลังน้ำใจ: 1
ออฟไลน์ ออฟไลน์

กระทู้: 10



ดูรายละเอียด
« ตอบ #12 เมื่อ: 16 กรกฎาคม 2009, 21:02:50 »

โค๊ด:
<?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
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 41
ออฟไลน์ ออฟไลน์

กระทู้: 1,979



ดูรายละเอียด เว็บไซต์
« ตอบ #13 เมื่อ: 16 กรกฎาคม 2009, 21:10:03 »

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

ผมสงสัยว่าในไฟล์มันมี ?> กี่ตัวครับ
บันทึกการเข้า

Develop site but can't develop life
ASIA
cyberbangkok
Newbie
*

พลังน้ำใจ: 1
ออฟไลน์ ออฟไลน์

กระทู้: 10



ดูรายละเอียด
« ตอบ #14 เมื่อ: 16 กรกฎาคม 2009, 21:13:16 »

ตามนี้เลยคะ

โค๊ด:
<?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
Verified Seller
เจ้าพ่อบอร์ดเสียว
*

พลังน้ำใจ: 181
ออฟไลน์ ออฟไลน์

กระทู้: 3,981



ดูรายละเอียด เว็บไซต์
« ตอบ #15 เมื่อ: 16 กรกฎาคม 2009, 21:14:09 »

ลองลบคอมเม้นออกหมมดเลยดิครับ
<?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();

?>

« แก้ไขครั้งสุดท้าย: 16 กรกฎาคม 2009, 21:18:27 โดย Normaderm » บันทึกการเข้า

alert
Verified Seller
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 50
ออฟไลน์ ออฟไลน์

กระทู้: 1,736



ดูรายละเอียด
« ตอบ #16 เมื่อ: 16 กรกฎาคม 2009, 21:17:30 »

คนตอบเยอะละ เข้ามาดูอย่างเดียวละกันครับ  Smiley
บันทึกการเข้า

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

พลังน้ำใจ: 1
ออฟไลน์ ออฟไลน์

กระทู้: 10



ดูรายละเอียด
« ตอบ #17 เมื่อ: 16 กรกฎาคม 2009, 21:18:18 »

โค๊ด:
<?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
Verified Seller
เจ้าพ่อบอร์ดเสียว
*

พลังน้ำใจ: 181
ออฟไลน์ ออฟไลน์

กระทู้: 3,981



ดูรายละเอียด เว็บไซต์
« ตอบ #18 เมื่อ: 16 กรกฎาคม 2009, 21:19:42 »

หุหุ สงสัยจะไปเออเร้อ ใน คลาส Bf_Download ละมั้ง... โค้ดยาวเหยียดเลย เห็นแล้ว สยอง  Tongue
บันทึกการเข้า

cyberbangkok
Newbie
*

พลังน้ำใจ: 1
ออฟไลน์ ออฟไลน์

กระทู้: 10



ดูรายละเอียด
« ตอบ #19 เมื่อ: 16 กรกฎาคม 2009, 21:28:51 »

ไฟล์ 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;  
        }
    }
}
?>
บันทึกการเข้า
หน้า: [1] 2  ทั้งหมด   ขึ้นบน
พิมพ์