PHP大文件储存示例,各种文件分割和合并(二进制分割与合并)

WBOY
Release: 2016-06-13 11:03:50
Original
1061 people have browsed it

PHP大文件存储示例,各种文件分割和合并(二进制分割与合并)

简单示例:

?

split.php

?

<?php$i    = 0;                               //分割的块编号$fp   = fopen("abc.wmv","rb");     //要分割的文件$file = fopen("split_hash.txt","a");     //记录分割的信息的文本文件while(!feof($fp)){        $handle = fopen("abc.wmv.{$i}","wb");        fwrite($handle,fread($fp,5000000));            //5000000 可以自定义.就是每个所分割的文件大小        fwrite($file,"qqdjz_002.wmv.{$i}\r\n");        fclose($handle);        unset($handle);        $i++;}fclose ($fp);fclose ($file);echo "ok";?>
Copy after login

?



join.php

?

<?php$mov  = file_get_contents("abc.txt");           //读取分割文件的信息$list = explode("\r\n",$mov);$fp   = fopen("split.wmv","ab");                  //合并后的文件名foreach($list as $value){<span style="white-space: pre;">	</span>if(!empty($value)) {        <span style="white-space: pre;">		</span>$handle = fopen($value,"rb");        <span style="white-space: pre;">	</span>fwrite($fp,fread($handle,filesize($value)));        <span style="white-space: pre;">	</span>fclose($handle);        <span style="white-space: pre;">	</span>unset($handle);<span style="white-space: pre;">	</span>}}fclose($fp);?>
Copy after login
?
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!