Php 带中断的文件上载

Php 带中断的文件上载,php,file-upload,server-side,Php,File Upload,Server Side,我想上传大文件到我的服务器,但我希望能够在上传过程中进行中断(例如,用户必须能够关闭计算机并在重新启动后继续) 我想我可以处理客户端上传,但我不知道如何使服务器端。在服务器端实现它的最佳方法是什么?PHP能够做到这一点吗?PHP是最有效的吗 非常感谢如果您设法在客户端将文件分块发布,您可以在服务器端执行以下操作: // set the path of the file you upload $path = $_GET['path']; // set the `appen

我想上传大文件到我的服务器,但我希望能够在上传过程中进行中断(例如,用户必须能够关闭计算机并在重新启动后继续)

我想我可以处理客户端上传,但我不知道如何使服务器端。在服务器端实现它的最佳方法是什么?PHP能够做到这一点吗?PHP是最有效的吗


非常感谢

如果您设法在客户端将文件分块发布,您可以在服务器端执行以下操作:

    // set the path of the file you upload
    $path = $_GET['path']; 
    // set the `append` parameter to 1 if you want to append to an existing file, if you are uploading a new chunk of data
    $append = intval($_GET['append']); 

    // convert the path you sent via post to a physical filename on the server
    $filename = $this->convertToPhysicalPath($path);

    // get the temporary file
    $tmp_file = $_FILES['file']['tmp_name'];

    // if this is not appending
    if ($append == 0) {
        // just copy the uploaded file
        copy($tmp_file, $filename);
    } else { 
        // append file contents
        $write_handle = fopen($filename, "ab");
        $read_handle = fopen($tmp_file, "rb");

        $contents = fread($read_handle, filesize($tmp_file));
        fwrite($write_handle, $contents);

        fclose($write_handle);
        fclose($read_handle);
    }

如果你正试图设计一个网络界面,允许任何人上传一个大文件,并恢复部分上传,尽管我不知道如何帮助你。但是,如果您只想以可恢复的方式将文件从您的计算机发送到服务器,那么您可以使用类似于
rsync
的工具。Rsync比较源和目标上的文件,然后只复制两者之间的差异。这样,如果您有50 GB的文件上载到服务器,然后更改了一个文件,rsync将很快检查所有其他文件是否相同,然后只发送一个更改的文件。这也意味着,如果通过rsync的传输中途中断,那么它将从中断的地方恢复

传统上,rsync是从命令行(终端)运行的,它默认安装在大多数Linux和Mac OS X上

rsync -avz /home/user/data sever:src/data 
这将把所有文件从/home/user/data传输到服务器上的src/data。如果随后更改/home/user/data中的任何文件,则可以再次运行该命令以重新同步该文件

如果您使用windows,最简单的解决方案可能是使用DeltaCopy,它是rsync周围的GUI