note 99863 added to features.file-upload.put-method
| From: | micronix at gmx dot net | Date: | Sat, 11 Sep 2010 02:43:53 +0000 |
| Subject: | note 99863 added to features.file-upload.put-method | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-172477@lists.php.net to get a copy of this message | ||
Hello PHP World After many Hours of worryness :=)
I have found the Solution for Resume or Pause Uploads
In this Code Snippet it is the Server Side not Client on any Desktop Programm you must use byte
ranges to calculate the uploaded bytes and missing of total bytes.
Here the PHP Code
$CHUNK = 8192;
try {
if (!($putData = fopen("php://input", "r")))
throw new Exception("Can't get PUT data.");
// now the params can be used like any other variable
// see below after input has finished
$tot_write = 0;
$tmpFileName = "/var/dev/tmp/PUT_FILE";
// Create a temp file
if (!is_file($tmpFileName)) {
fclose(fopen($tmpFileName, "x")); //create the file and close it
// Open the file for writing
if (!($fp = fopen($tmpFileName, "w")))
throw new Exception("Can't write to tmp file");
// Read the data a chunk at a time and write to the file
while ($data = fread($putData, $CHUNK)) {
$chunk_read = strlen($data);
if (($block_write = fwrite($fp, $data)) != $chunk_read)
throw new Exception("Can't write more to tmp file");
$tot_write += $block_write;
}
if (!fclose($fp))
throw new Exception("Can't close tmp file");
unset($putData);
} else {
// Open the file for writing
if (!($fp = fopen($tmpFileName, "a")))
throw new Exception("Can't write to tmp file");
// Read the data a chunk at a time and write to the file
while ($data = fread($putData, $CHUNK)) {
$chunk_read = strlen($data);
if (($block_write = fwrite($fp, $data)) != $chunk_read)
throw new Exception("Can't write more to tmp file");
$tot_write += $block_write;
}
if (!fclose($fp))
throw new Exception("Can't close tmp file");
unset($putData);
}
// Check file length and MD5
if ($tot_write != $file_size)
throw new Exception("Wrong file size");
$md5_arr = explode(' ', exec("md5sum $tmpFileName"));
$md5 = $md5sum_arr[0];
if ($md5 != $md5sum)
throw new Exception("Wrong md5");
} catch (Exception $e) {
echo '', $e->getMessage(), "\n";
}
----
Server IP: 69.147.83.197
Probable Submitter: 217.227.72.195
----
Manual Page -- http://www.php.net/manual/en/features.file-upload.put-method.php
Edit -- https://master.php.net/note/edit/99863
Del: integrated -- https://master.php.net/note/delete/99863/integrated
Del: useless -- https://master.php.net/note/delete/99863/useless
Del: bad code -- https://master.php.net/note/delete/99863/bad+code
Del: spam -- https://master.php.net/note/delete/99863/spam
Del: non-english -- https://master.php.net/note/delete/99863/non-english
Del: in docs -- https://master.php.net/note/delete/99863/in+docs
Del: other reasons-- https://master.php.net/note/delete/99863
Reject -- https://master.php.net/note/reject/99863
Search -- https://master.php.net/manage/user-notes.php