Use php to enable resumable Upload

Source: Internet
Author: User
Using php to download files supports resumable php to download files, and supports resumable download & nbsp; & nbsp; ob_start (); $ sizefilesize ($ file_dir. $ resumable download is supported for file downloads using php.
Use php to download files and support resumable download
Ob_start (); $ size = filesize ($ file_dir. $ file_name); // Header of the input file tag ("Content-type: application/octet-stream"); Header ("Cache-Control: must-revalidate, post-check = 0, pre-check = 0 "); Header (" Content-length :". $ size); $ encoded_filename = urlencode ($ down_name); $ encoded_filename = str_replace ("+", "% 20", $ encoded_filename ); $ ua = $ _ SERVER ["HTTP_USER_AGENT"]; // process the download object name if (preg_match ("/MSIE /", $ Ua) {header ('content-Disposition: attachment; filename = "'. $ encoded_filename. '"');} else if (preg_match ("/Firefox/", $ ua) {header ('content-Disposition: attachment; filename * = "utf8 \'\''. $ down_name. '"');} else {header ('content-Disposition: attachment; filename = "'. $ down_name. '"');} $ fp = fopen ($ file_dir. $ file_name, "r"); // open the file if (isset ($ _ SERVER ['http _ range']) & ($ _ SERVER ['ht" TP_RANGE ']! = "") & Preg_match ("/^ bytes = ([0-9] +)-/I", $ _ SERVER ['http _ range'], $ match) & ($ match [1] <$ size) {$ range = $ match [1]; fseek ($ fp, $ range ); header ("HTTP/1.1 206 Partial Content"); // header ("Date :". gmdate ("D, d m y h: I: s "). "GMT"); header ("Last-Modified :". gmdate ("D, d m y h: I: s", filemtime ($ file_dir. $ file_name )). "GMT"); header ("Accept-Ranges: bytes"); $ rangesize = ($ size-$ range)> 0? ($ Size-$ range): 0; header ("Content-Length :". $ rangesize); header ("Content-Range: bytes ". $ range. '-'. ($ size-1 ). "/". $ size); // header ("Connection: close ". "\ n"); // header ("Connection: close ". "");} else {header ("Content-Length :". (string) ($ size); header ("Accept-Ranges: bytes"); $ range = 0; header ("Content-Range: bytes ". $ range. '-'. ($ size-1 ). "/". $ size) ;}fpassthru ($ fp); ob_end_flush (); fclose ($ fp); exit;

In this way, resumable download is supported. It is intended to be useful to users who use php for download.

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.