Php simple method for resumable download

Source: Internet
Author: User
This article describes how to implement resumable download in PHP. It involves some php skills related to file transmission and has some reference value. For more information, see

This article describes how to implement resumable download in PHP. It involves some php skills related to file transmission and has some reference value. For more information, see

This example describes how to implement resumable download in PHP. Share it with you for your reference. The details are as follows:

$ Fname = 'HTTP: // XXXX/MMLDZG.mp3 '; $ fp = fopen ($ fname, 'rb'); $ fsize = filesize ($ fname ); if (isset ($ _ SERVER ['HTTP _ range']) & ($ _ SERVER ['HTTP _ range']! = "") & Preg_match ("/^ bytes = ([0-9] +)-$/I", $ _ SERVER ['HTTP _ range'], $ match) & ($ match [1] <$ fsize) {$ start = $ match [1];} else {$ start = 0 ;} @ header ("Cache-control: public"); @ header ("Pragma: public"); if ($ star --> 0) {fseek ($ fp, $ start ); header ("HTTP/1.1 206 Partial Content"); Header ("Content-Length :". ($ fsize-$ start); Header ("Content-Ranges: bytes ". $ start. "-". ($ fsize-1 ). "http : // Www.jb51.net /". $ fsize) ;}else {header ("Content-Length: $ fsize"); Header ("Accept-Ranges: bytes") ;}@ header ("Content-Type: application/octet-stream "); @ header (" Content-Disposition: attachment?filename=mmdld#"); fpassthru ($ fp); fpassthru (); // all the remaining data at the pointer of the function output file.

This function reads the given file pointer from the current location to EOF and writes the result to the output buffer.

I hope this article will help you with php programming.

,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.