plupload-handler-php icon indicating copy to clipboard operation
plupload-handler-php copied to clipboard

write final file procedure

Open valiradut opened this issue 10 years ago • 1 comments

Hello,

When using chunks, the final file is recomposed from chunk files. This procedure takes a lot of time: takes as much as you were copying the file intro another file (on se same disk). Consider a copy of 10GB file, thats too much.

I've changed the class, using the example from here https://github.com/moxiecode/plupload/blob/master/examples/upload.php loose "write_file_to" and "write_chunks_to_file" functions

and leave only

$file_path = rtrim($conf['target_dir'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file_name;

            // Open temp file
            if (!$out = @fopen("{$file_path}.part", $conf['chunks'] ? "ab" : "wb")) {
                throw new Exception('', PLUPLOAD_OUTPUT_ERR);
            }

            if (!empty($_FILES)) {
                if ($_FILES["file"]["error"] || !is_uploaded_file($_FILES["file"]["tmp_name"])) {
                    throw new Exception('', PLUPLOAD_MOVE_ERR);
                }

                // Read binary input stream and append it to temp file
                if (!$in = @fopen($_FILES["file"]["tmp_name"], "rb")) {
                    throw new Exception('', PLUPLOAD_INPUT_ERR);
                }
            }

            while ($buff = fread($in, 4096)) {
                fwrite($out, $buff);
            }

            @fclose($out);
            @fclose($in);

            // Check if file has been uploaded
            if (!$conf['chunks'] || $conf['chunk'] == $conf['chunks'] - 1) {
                // Strip the temp .part suffix off
                rename("{$file_path}.part", $file_path);
            }

            return array(
            'name' => $file_name,
            'path' => $file_path,
            //'size' => filesize($file_path)
            );

thank you.

valiradut avatar Oct 01 '15 12:10 valiradut

Having chunks separate makes it possible to upload them in parallel (so it won't be clear which one will arrive when). It is also crucial for long and important updates to be able to checksum each chunk to make sure that they are what they should be.

But the issue that you brought up here is definitely there, so we will probably end up with a configuration option for this.

jayarjo avatar Jul 26 '16 07:07 jayarjo