Split big files using PHP

后端 未结 9 1219
感动是毒
感动是毒 2020-12-06 02:05

I want to split huge files (to be specific, tar.gz files) in multiple part from php code. Main reason to do this is, php\'s 2gb limit on 32bit system.

SO I want to s

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-06 02:35

    $handle = fopen('source/file/path','r'); 
            $f = 1; //new file number
            while(!feof($handle))
            {
                $newfile = fopen('newfile/path/'.$f.'.txt','w'); //create new file to write to with file number
                for($i = 1; $i <= 5000; $i++) //for 5000 lines
                {
                    $import = fgets($handle);
                    //print_r($import);
                    fwrite($newfile,$import);
                    if(feof($handle))
                    {break;} //If file ends, break loop
                }
                fclose($newfile);
                $f++; //Increment newfile number
            }
            fclose($handle);
    

提交回复
热议问题