选择语言 :

 Core_File::split

Split a file into pieces matching a specific size. Used when you need to split large files into smaller pieces for easy transmission.

$count = File::split($file);
integer Core_File::split( string $filename [, string $piece_size = integer 10 , integer $storage = string(7) "default" ] )

参数列表

参数 类型 描述 默认值
$filename string File to be split
$piece_size string Directory to output to, defaults to the same directory as the file integer 10
$storage integer Size, in MB, for each piece to be string(7) "default"
返回值
  • integer The number of pieces that were created
File: ./core/classes/file.class.php
public static function split($filename, $piece_size = 10 , $storage = 'default')
{
       $info = File::check_and_get_path($filename);

       if (File::can_do_run($storage))
       {
   		// Open the input file
   		$file = fopen($filename, 'rb');

   		// Change the piece size to bytes
   		$piece_size = floor($piece_size * 1024 * 1024);

   		// Write files in 8k blocks
   		$block_size = 1024 * 8;

   		// Total number of peices
   		$peices = 0;

   		while (!feof($file))
   		{
   			// Create another piece
   			$peices += 1;

   			// Create a new file piece
   			$piece = str_pad($peices, 3, '0', STR_PAD_LEFT);
   			$piece = fopen($filename.'.'.$piece, 'wb+');

   			// Number of bytes read
   			$read = 0;

   			do
   			{
   				// Transfer the data in blocks
   				fwrite($piece, fread($file, $block_size));

   				// Another block has been read
   				$read += $block_size;
   			}
   			while ($read < $piece_size);

   			// Close the piece
   			fclose($piece);
   		}

   		// Close the file
   		fclose($file);

   		return $peices;
       }
       else
       {
           return File::call_http_host($storage,'file/split',$info[0], $info[1], $piece_size);
       }
}