Skip to content

Commit 72f438c

Browse files
committed
make use of ResumableTotalChunks requestParam
1 parent 988948f commit 72f438c

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/Resumable.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class Resumable
4747
'filename' => 'filename',
4848
'chunkNumber' => 'chunkNumber',
4949
'chunkSize' => 'chunkSize',
50-
'totalSize' => 'totalSize'
50+
'totalSize' => 'totalSize',
51+
'totalChunks' => 'totalChunks'
5152
];
5253

5354
const WITHOUT_EXTENSION = true;
@@ -178,12 +179,12 @@ public function handleTestChunk()
178179
$filename = $this->resumableParam($this->resumableOption['filename']);
179180
$chunkNumber = $this->resumableParam($this->resumableOption['chunkNumber']);
180181
$chunkSize = $this->resumableParam($this->resumableOption['chunkSize']);
181-
$totalSize = $this->resumableParam($this->resumableOption['totalSize']);
182+
$totalChunks = $this->resumableParam($this->resumableOption['totalChunks']);
182183

183184
if (!$this->isChunkUploaded($identifier, $filename, $chunkNumber)) {
184185
return $this->response->header(204);
185186
} else {
186-
if ($this->isFileUploadComplete($filename, $identifier, $chunkSize, $totalSize)) {
187+
if ($this->isFileUploadComplete($filename, $identifier, $totalChunks)) {
187188
$this->isUploadComplete = true;
188189
$this->createFileAndDeleteTmp($identifier, $filename);
189190
return $this->response->header(201);
@@ -200,14 +201,14 @@ public function handleChunk()
200201
$filename = $this->resumableParam($this->resumableOption['filename']);
201202
$chunkNumber = $this->resumableParam($this->resumableOption['chunkNumber']);
202203
$chunkSize = $this->resumableParam($this->resumableOption['chunkSize']);
203-
$totalSize = $this->resumableParam($this->resumableOption['totalSize']);
204+
$totalChunks = $this->resumableParam($this->resumableOption['totalChunks']);
204205

205206
if (!$this->isChunkUploaded($identifier, $filename, $chunkNumber)) {
206207
$chunkFile = $this->tmpChunkDir($identifier) . DIRECTORY_SEPARATOR . $this->tmpChunkFilename($filename, $chunkNumber);
207208
$this->moveUploadedFile($file['tmp_name'], $chunkFile);
208209
}
209210

210-
if ($this->isFileUploadComplete($filename, $identifier, $chunkSize, $totalSize)) {
211+
if ($this->isFileUploadComplete($filename, $identifier, $totalChunks)) {
211212
$this->isUploadComplete = true;
212213
$this->createFileAndDeleteTmp($identifier, $filename);
213214
return $this->response->header(201);
@@ -265,13 +266,9 @@ public function resumableParams()
265266
}
266267
}
267268

268-
public function isFileUploadComplete($filename, $identifier, $chunkSize, $totalSize)
269+
public function isFileUploadComplete($filename, $identifier, $totalChunks)
269270
{
270-
if ($chunkSize <= 0) {
271-
return false;
272-
}
273-
$numOfChunks = intval($totalSize / $chunkSize) + ($totalSize % $chunkSize == 0 ? 0 : 1);
274-
for ($i = 1; $i <= $numOfChunks; $i++) {
271+
for ($i = 1; $i <= $totalChunks; $i++) {
275272
if (!$this->isChunkUploaded($identifier, $filename, $i)) {
276273
return false;
277274
}

0 commit comments

Comments
 (0)