PHP Classes

Why this can NOT merge file more than 4MB? would you fix it?

Recommend this page to a friend!

      Split and merge files  >  All threads  >  Why this can NOT merge file more...  >  (Un) Subscribe thread alerts  
Subject:Why this can NOT merge file more...
Summary:Package rating comment
Messages:2
Author:JrrMaster
Date:2012-04-19 02:45:21
 

JrrMaster rated this package as follows:

Utility: Good
Consistency: Not sure
Examples: Insufficient

  1. Why this can NOT merge file more...   Reply   Report abuse  
Picture of JrrMaster JrrMaster - 2012-04-19 02:45:21
Why this can NOT merge file more than 4MB?
would you fix it?

  2. Re: Why this can NOT merge file more...   Reply   Report abuse  
Picture of Mck Mck - 2015-02-02 17:09:35 - In reply to message 1 from JrrMaster
The merge method could be rewritten to not read the all parts into memory.

/*------------------------------------------------------------------
- MERGE -
- This function merges splited files that are splited with above -
- split_file function. -
--------------------------------------------------------------------*/
function merge_file($merged_file_name,$parts_num)
{
$content='';
//put splited files content into content
$mhandle=fopen($merged_file_name, 'wb') or die("error creating/opening merged file");
for($i=0;$i<$parts_num;$i++)
{
$file_size = filesize('splited_'.$i);
$handle = fopen('splited_'.$i, 'rb') or die("error opening file");
$content = fread($handle, $file_size) or die("error reading file");
fclose($handle);
//write content to merged file
fwrite($mhandle, $content) or die("error writing to merged file");
}
fclose($mhandle);
return 'OK';
}//end of function merge_file