Home >Backend Development >PHP Tutorial >Detailed explanation of file splitting and merging using PHP to implement breakpoint resume transfer

Detailed explanation of file splitting and merging using PHP to implement breakpoint resume transfer

墨辰丷
墨辰丷Original
2018-05-29 15:50:392149browse

This article mainly introduces the file segmentation and merging of PHP breakpoint resume transfer in detail. It has certain reference value. Interested friends can refer to

php to implement breakpoint resume transfer. You need to split the large file into multiple small files and then upload them individually. Merge after transmission.

│ merge.php – merge file script
│ merge.zip – merged file
│ socket.zip – file that needs to be split
│ split.php – Split file script

└─split – Split small file directory

The following is the source code

split.php


<?php

$fp = fopen("socket.zip", "rb");
$filesize = 10;
$i = 0;
$no = 1;
while(!feof($fp))
{
  $file = fread($fp, $filesize);

  $fp2 = fopen("./split/socket.port".sprintf("%04d",$no).".".$i."-".($i+$filesize).".tmp", "wb");
  fwrite($fp2, $file, $filesize);
  fclose($fp2);
  $i+=$filesize+1;
$no++;
}

fclose($fp);


merge.php


<?php
$filelist = glob(&#39;./split/*socket*.tmp&#39;);
$filesize = 10;

//print_r($filelist);
$mergeFileName = &#39;merg.zip&#39;;

unlink($mergeFileName);
  $fp2 = fopen($mergeFileName,"w+");
foreach($filelist as $k => $v)
{
  $fp = fopen($v, "rb");
   $content = fread($fp, $filesize);

   fwrite($fp2, $content, $filesize);
   unset($content);
   fclose($fp);
   echo $k,"\n";
}
  fclose($fp2);


The above is this article The entire content, I hope it will be helpful to everyone's study.


Related recommendations:

PHP large file storage example, various file splitting and merging (binary splitting and merging)

How to split and merge files for php breakpoint resume_PHP

PHP large file storage example, various file splitting and merging ( Binary split and merge)


The above is the detailed content of Detailed explanation of file splitting and merging using PHP to implement breakpoint resume transfer. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn