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

标签 php file copy

我需要通过 PHP 复制一些大文件 (6 GB)。我怎样才能做到这一点? Copy() 函数做不到。

我在 Windows 32/64 上使用 PHP 5.3。

最佳答案

应该这样做。

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 - 在 PHP 中复制大文件(超过 2 GB),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6564643/

相关文章:

php - guzzlehttp 在 Laravel 项目上抛出错误 - strtolower() : Argument #1 ($string) must be of type string, int 给出

php - Laravel 5.4 无需数据库的基本身份验证

java - 在没有 getImage() 的 Applet 中加载图像?

linux - 为什么输入数据后无法保存VI文件?

java - 在Java中使用文本文件携带命令

c++ - 将字符长度从数组复制到 std::string

php - 未定义的属性:Illuminate\Database\Query\Builder::$auth

php - 如何在 php 中测试数组的索引是否与数组的另一个索引相等?

C++ 对象构造函数通过 const 引用复制传递

PHP 在生成文档时在服务器上创建文档副本