在PHP中复制大型文件(超过2 GB) [英] Copy large files (over 2 GB) in PHP
本文介绍了在PHP中复制大型文件(超过2 GB)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要通过PHP复制一些大文件(6 GB)。我该怎么办?
Copy()
函数不能这样做。
I need to copy some big file (6 GB) via PHP. How can I do that?
The Copy()
function can't do it.
我在Windows上使用PHP 5.3 32/64。
I am using PHP 5.3 on Windows 32/64.
推荐答案
这应该可以。
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
}
这篇关于在PHP中复制大型文件(超过2 GB)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文