Copy large files (over 2 GB) in PHP
This should do it.
function chunked_copy($from, $to) { # 1 meg at a time, you can adjust this. $buffer_size = 1048576; $ret = 0; $fin = fopen($from, "rb"); $fout = fopen($to, "w"); while(!feof($fin)) { $ret += fwrite($fout, fread($fin, $buffer_size)); } fclose($fin); fclose($fout); return $ret; # return number of bytes written}
If copy
doesnt work, you can try with
Example
stream_copy_to_stream( fopen('/path/to/input/file.txt', 'r'), fopen('/path/to/output/file.txt', 'w+'));