I need to copy some big file (6 GB) via PHP. How can I do that?
The Copy()
function can't do it.
I am using PHP 5.3 on Windows 32/64.
By changing the upload_max_filesize limit in the php. ini file. By implementing file chunk upload, that splits the upload into smaller pieces an assembling these pieces when the upload is completed.
Courier a Hard Drive If you have lots of large files to send then filling up a hard drive and sending it off with a courier is an effective way to transfer files. Physically sending a large volume of files via a courier is often much faster than attempting to upload those files through a broadband connection.
But you can still use a few ways to copy and paste faster. Hold Ctrl and click multiple files to select them all, no matter where they are on the page. To select multiple files in a row, click the first one, then hold Shift while you click the last one. This lets you easily pick a large number of files to copy or cut.
The copy() function in PHP is used to copy a file from source to target or destination directory. It makes a copy of the source file to the destination file and if the destination file already exists, it gets overwritten. The copy() function returns true on success and false on failure.
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 you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With