PHP Breakpoint Continuation of the file segmentation merge instance detailed

Source: Internet
Author: User
This article is mainly for you to introduce the PHP breakpoint continuation of the file segmentation and merging, with a certain reference value, interested in small partners can refer to

PHP implementation of the breakpoint continuation, you need to split the large file into a number of small files, and then single upload. After the transfer is completed in the merge.

│merge.php– Merging file scripts
│merge.zip– after merging files
│socket.zip– files that need to be split
│split.php– Split File Script

└─split– small file directory after splitting

Here is the source code

split.php

<?PHP$FP = fopen ("Socket.zip", "RB"), $filesize = ten; $i = 0; $no = 1;while (!feof ($fp)) {  $file = fread ($fp, $filesize) ;  $FP 2 = fopen ("./split/socket.port". sprintf ("%04d", $no). ".". $i. " -". ($i + $filesize). ". TMP "," WB ");  Fwrite ($fp 2, $file, $filesize);  Fclose ($fp 2);  $i + = $filesize +1; $no + +;} Fclose ($FP);

merge.php

<?php$filelist = Glob ('./split/*socket*.tmp '); $filesize = 10;//print_r ($  filelist); $mergeFileName = ' merg.zip '; unlink ($mergeFileName);   $FP 2 = fopen ($mergeFileName, "w+"), foreach ($filelist as $k = = $v) {$fp = fopen ($v, "RB");   $content = Fread ($fp, $filesize);   Fwrite ($fp 2, $content, $filesize);   Unset ($content);   Fclose ($FP);  echo $k, "\ n";} Fclose ($fp 2); 

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.