文件上传中断

I'd like to upload large files to my server, but i would like to be able to make breaks (for example, the user must be able to shut down his computer and to continue after reboot) in the upload process.

I think i can handle the client side upload, but I don't know how to make the server side. What is the best way to make it on the server side? Is PHP able to do that ? Is PHP the most efficient?

Thanks a lot

If you manage to do the client side do post the file in chunks, you could do something like this on the server side:

    // 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);
    }

If you are trying to design a web interface to allow anyone to upload a large file and resume the upload part way though I don't know how to help you. But if all you want to do is get files from you computer to a server in a resume-able fashion you may be able to use a tool like rsync. Rsync compare the files on the source and destination, and then only copies the differences between the two. This way if you have 50 GB of files that you upload to your server and then change one, rsync will very quickly check that all the other files are the same, and then only send your one changed file. This also means that if a transfer is interrupted part way through rsync will pick up where it left off.

Traditionally rsync is run from the command line (terminal) and it is installed by default on most Linux and Mac OS X.

rsync -avz /home/user/data sever:src/data 

This would transfer all files from /home/user/data to the src/data on the server. If you then change any file in /home/user/data you can run the command again to resync it.

If you use windows the easiest solution is probably use DeltaCopy which is a GUI around rsync.download