PHP implementation of large file cutting and merging steps

Source: Internet
Author: User
Tags fread
This time for everyone to bring PHP to achieve large file cutting and merging steps, PHP implementation of large file cutting and merger considerations, the following is the actual case, together to see.

Split code

split.php

<?php$i  = 0;                 Split block number $fp  = fopen ("Hadoop.sql", "RB");      The file to be split $file = fopen ("Split_hash.txt", "a");    The text file that records the split information, the actual production environment exists redis more suitable while (!feof ($fp)) {    $handle = fopen ("hadoop.{ $i}.sql "," WB ");    Fwrite ($handle, Fread ($fp, 5242880));//Cut the block size 5m    fwrite ($file, "hadoop.{ $i}.sql\r\n ");    Fclose ($handle);    Unset ($handle);    $i + +;} Fclose ($FP); fclose ($file); echo "OK";

Merge code

merge.php

<?php$hash = file_get_contents ("Split_hash.txt"); Read the information of the segmented file $list = explode ("\ r \ n", $hash); $fp = fopen ("Hadoop2.sql", "AB");    The merged file name, foreach ($list as $value) {  if (!empty ($value)) {    $handle = fopen ($value, "RB");    Fwrite ($fp, Fread ($handle, FileSize ($value)));    Fclose ($handle);    Unset ($handle);  }} Fclose ($FP); echo "OK";

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

thinkphp Framework Let page redirection method summary

PHP uses regular expressions to match city-province

Related Article

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.