在 PHP 中复制大文件(超过 2 GB) [英] Copy large files (over 2 GB) in PHP

查看:29
本文介绍了在 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 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
}

这篇关于在 PHP 中复制大文件(超过 2 GB)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆