AdminTalk - Talk to Learn

Navigation
Go Back   AdminTalk - Talk to Learn > Webmaster Area > Programming Language > Other
Other Trao đổi về những vấn đề khác trong công nghệ phần mềm như Analyzing, Designing, Defining Solution Architures…

Đề mục chính

Cấu trúc diễn đàn
Thông tin tổng hợp
Thông báo và quy định chung
Đóng góp ý kiến
Những bài viết có giá trị
Tin tức công nghệ
•• Tin tức công nghệ thông tin
•• Doanh Nghiệp & Người Tiêu Dùng
Premium Server, Hosting Support
Web Hosting / Domain
•• Kiến thức cơ bản về Web Hosting/Domain
•• Plesk - CPanel
Server / VPS
•• Kiến thức cơ bản Server - VPS
•• Server Review/ Hardware
•• Mail Server - AntiSPAM
Virtuozzo - VMWare - HyperV
•• For Windows
•• For Linux
Security
•• Mạng Wan - Lan
•• Internet - Virus - Hacker
VoIP
•• Kiến Thức Cơ Bản VoIP
•• Phần Cứng VoIP
•• Phần Mềm VoIP
•• Nhà cung cấp VoIP
Server Operating System
Linux Server
Windows Server 200x
Computer Supports and Discussion
Operating System
•• Hệ điều hành Linux
•• Hệ điều hành Windows
•• Hệ điều hành Mac
•• Hệ điều hành Chrome
Laptop, Netbook
Hardware
•• Cpu Intel
•• Cpu AMD
•• PSU, Overclocking & Cooling
•• Mainboard & Memory
•• Đồ họa máy tính
•• Kinh nghiệm
Software
•• Linux Apps
•• Windows Apps
Webmaster Area
Webmaster talk
Programming Language
•• HTML & CSS
•• PHP
•• C++ / C#
•• .NET
•• Java
•• Other
Graphic & Mutimedia
SEO (Search Engine Optimization)
Browsers
•• Mozilla Firefox
•• Chrome
•• Internet Explorer
Thủ Thuật Internet
Thương mại điện tử
•• Hình thức thanh toán
•• Giải pháp
HiTech, Mobile, Movies, Music, eBooks, Relax
Tablet PC
•• iPad
Mobile
•• iPhone
•• BlackBerry
•• Others
Movies
•• Download phim HD
•• Download phim DVD
Music
•• Download nhạc Lossless Album
•• Download nhạc Lossless tuyển chọn
eBooks - Tài liệu
•• Tin học - Lập trình
•• Khoa học - Kỹ thuật
•• Ngoại Ngữ
•• Tutorials - Training
•• Kinh tế
•• Thể Loại Khác
Bài học trong cuộc sống
AdminTalk – Talk to You
Introduce Youself
Off topic/ Chatting
Mua bán - Rao vặt - Tuyển dụng
Quảng cáo
Tuyển dụng

Bầu chọn mới nhất
Bạn nghĩ sao về công nghệ USB 3.0 ?

Rất tuyệt! Sẽ sử dụng ngay nếu được bán trên thị trường: 47.37%

Tốt hơn USB 2.0 , nhưng giá có thể mắc hơn nhiều: 42.11%

Bình thường thôi, công nghệ luôn thay đổi mà: 10.53%

Không quan tâm lắm: 0%
Voters: 38. You may not vote on this poll

Thống kê
Đề tài: 10641
Bài gửi: 12205
Thành viên: 20,207
Thành viên tích cực: 81
Xin cùng nhau chào đón thành viên mới nhất: buixuantu
Kỷ lục: 624 người đã ghé thăm 17/11/2010 lúc 06:16 AM.
Thành viên mới:
Hôm qua
- buixuantu
Hôm qua
- baophuc0711
08/02/2012
- ddvtien
08/02/2012
- thanhtam1028
08/02/2012
- goodhealthvn1
08/02/2012
- honghobao286
07/02/2012
- condau
07/02/2012
- timlaibautroi7408
07/02/2012
- NguyenLien
07/02/2012
- quydona

Số người đang xem
View Who's Online Thành viên: 3
Khách: 36
Tổng: 39
Nhóm: 0
Nhóm:  
Thành viên:  aviomobile, aviovn8, linhshop1989
Mở Sổ Bạn Bè

Trả lời
 
LinkBack Ðiều Chỉnh Kiếm Trong Bài Xếp Bài

  #1 (permalink)
Old 01/03/2010, 11:57 PM
[PHP] Giới hạn Tốc độ download bằng php - LIMIT Download

Chip
Admintalk's Staff
can't stop talking
 
Chip's Avatar
 
Tham gia ngày: Apr 2008
Nơi Cư Ngụ: Germany
Bài gởi: 4,003
My Mood:
Thanks: 27
Thanked 210 Times in 152 Posts
VP: 0.00
Donate
Send a message via MSN to Chip Send a message via Yahoo to Chip Send a message via Skype™ to Chip
PHP Code:
<?php

/**

 * Download with limited speed class file.



 * Licensed under New BSD License

 * @filesource download_limited.php



 * @since           php 5.0

 * @version         $Revision: 1 $



 * @lastmodified    $Date: 2008-08-18 09:45:49 -0500 (Sat, 18 Oct 2008) $

 * @license         http://www.freebsd.org/copyright/freebsd-license.html New BSD Style License

 */



class DownloadLimited

{       

        
/**

         * Send the local file to client with limit download rate as user view file name

         *

         * @param  string $localFile file to send

         * @param  string $userViewFileName filename client will see

         * @param  float  $downloadRate download limit speed in kb/s (ex: 50 kb/s)

         * @return no return

         */

        
function sendFile($localFile,$userViewFileName,$downloadRate)

        {

                
/** check file exists

                 * @see file_exists

                */

                
if(!file_exists($localFile))

                {

                        throw new 
Exception('File not found execption file :'.$localFile.' not found');

                }       

                
/** check file is file 

                 * @see is_file

                */

                
if(!is_file($localFile)) 

                {

                        throw new 
Exception($localFile.' not is a file');

                }

                if(!
is_readable($localFile))

                {

                        throw new 
Exception('file '.$localFile.' not readable ');

                }

                
// send headers

                
header('Cache-control: private');

                
header('Content-Type: application/octet-stream');

                
header('Content-Length: '.filesize($localFile));

                
header('Content-Disposition: filename='.$userViewFileName);



                
// flush header content 

                
flush();

                
// open file stream

                
$file fopen($localFile, &quot;r&quot;);

                while(!
feof($file)) 

                {



                        
// send the current file part to the browser

                        
print fread($fileround($downloadRate 1024));



                        
// !important flush the content to the browser

                        
flush();



                        
// !important sleep one second

                        
sleep(1);

                }



                
// close file stream

                
fclose($file);

                        



        }

        
/**

         * Send the string data to client with limit download rate as user view file name

         *

         * @param  string string data  to send include ascii,utf-8 character

         * @param  string $userViewFileName filename client will see

         * @param  float  $downloadRate download limit speed in kb/s (ex: 50 kb/s)

         * @return no return

         */

        
function sendString($data,$userViewFileName,$downloadRate)

        {

                
// send headers

                
header('Cache-control: private');

                
header('Content-Type: application/octet-stream');

                
header('Content-Length: '.strlen($data));

                
header('Content-Disposition: filename='.$userViewFileName);

                
// flush header content 

                
flush();

                

                
$start=0;

                
$sendSize=0;

                while(
$sendSize<strlen($data))

                {

                        
$sendSize=round($downloadRate*1024);

                        print 
substr($data,$start,$sendSize);

                        
$start=$sendSize;

                        
// !important flush the content to the browser

                        
flush();



                        
// !important sleep one second

                        
sleep(1);

                }

        }

        

}

?>
[/quote]

Bài viết cùng chủ đề:
Chip vẫn chưa có mặt trong diễn đàn  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Trả Lời Với Trích Dẫn
Trả lời

Bookmarks


Ðang đọc: 1 (0 thành viên và 1 khách)
 
Ðiều Chỉnh Kiếm Trong Bài
Kiếm Trong Bài:

Kiếm Chi Tiết
Xếp Bài

Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt
Trackbacks are Mở
Pingbacks are Mở
Refbacks are Mở

Chuyển đến



Múi giờ GMT. Hiện tại là 03:06 AM.
Powered by: vBulletin - Copyright © 2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.AdminTalk.vn
Powered by vBCMS® 1.2.5 ©2002 - 2012 VinaCIS® Corporation