Example #1
0
 /**
  * Join a split file into a whole file. Does the reverse of [File::split].
  *
  *     $count = File::join($file);
  *
  * @param string   split filename, without .000 extension
  * @param string   output filename, if different then an the filename
  * @param string $storage 物理存储组,不传则为默认
  * @return integer  The number of pieces that were joined.
  */
 public static function join($filename, $storage = 'default')
 {
     $info = File::check_and_get_path($filename);
     if (File::can_do_run($storage)) {
         // Open the file
         $file = fopen($filename, 'wb+');
         // Read files in 8k blocks
         $block_size = 1024 * 8;
         // Total number of peices
         $pieces = 0;
         while (is_file($piece = $filename . '.' . str_pad($pieces + 1, 3, '0', STR_PAD_LEFT))) {
             // Read another piece
             $pieces += 1;
             // Open the piece for reading
             $piece = fopen($piece, 'rb');
             while (!feof($piece)) {
                 // Transfer the data in blocks
                 fwrite($file, fread($piece, $block_size));
             }
             // Close the peice
             fclose($piece);
         }
         return $pieces;
     } else {
         return File::call_http_host($storage, 'file/join', $info[0], $info[1]);
     }
 }