Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write final file procedure #5

Open
valiradut opened this issue Oct 1, 2015 · 1 comment
Open

write final file procedure #5

valiradut opened this issue Oct 1, 2015 · 1 comment

Comments

@valiradut
Copy link

valiradut commented Oct 1, 2015

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.

@jayarjo
Copy link
Contributor

jayarjo commented Jul 26, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants