在 PHP 中复制大文件(超过 2 GB)

2022-01-20 00:00:00 复制 file php

我需要通过 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 32/64 上使用 PHP 5.3.

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
}

相关文章