PHP Tips for file transfer

Source: Internet
Author: User
Tags ranges
This article mainly introduces PHP for file transfer of the relevant skills, interested in the reference of friends, I hope to be helpful to everyone.

Specific 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:pu Blic "); @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). "/" . $fsize);} else {  header ("Content-length: $fsize");  Header ("Accept-ranges:bytes");} @header ("Content-type:application/octet-stream"); @header ("Content-disposition:attachment;filename=mmdld.mp3"); Fpassthru ($FP); Fpassthru ();//The function outputs all remaining data at the file pointer.

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

Summary : The above is the entire content of this article, I hope to be able to help you learn.

Related recommendations:

PHP gets all the properties in a class based on reflection

The method of implementing infinite pole classification tree in PHP

The PDO data Access abstraction layer in PHP

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.