Question

I am importing data feed into mywebsite.My datafeed files are came from tar.gz format. The file size is is very large upto 10 gb. i need to split tar.gz file and then upload to database. How can i split tar.gz single file to multiple file. Please Guide me.

Was it helpful?

Solution

You can create several parts like this:

$fileName = 'something_big.tar.gz';
$fileSize = filesize($fileName);
$parts = 10;
$partSize = ceil($fileSize / 10);

$f_in = fopen($fileName, 'rb');
for ($i = 0; $i < $parts; ++$i) {
    $f_out = fopen("$fileName.$i", 'wb');
    stream_copy_to_stream($f_in, $f_out, $partSize);
    fclose($f_out);
}
fclose($f_in);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top