Skip to content

Commit 62c3fff

Browse files
authored
Merge pull request dilab#38 from code-lts/bugfixes
Some bugfixes from my fork
2 parents d7a4f11 + 658e854 commit 62c3fff

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ To install, use composer:
1010
## How to use
1111
**upload.php**
1212

13-
```
13+
```php
1414
<?php
1515
include 'vendor/autoload.php';
1616

@@ -20,7 +20,7 @@ use Dilab\Resumable;
2020

2121
$request = new SimpleRequest();
2222
$response = new SimpleResponse();
23-
// optional instanceId to seperate uploads from diffrent users like if two users want to upload untitled.jpg there would be no conflict anymore
23+
// optional instanceId to separate uploads from diffrent users like if two users want to upload untitled.jpg there would be no conflict anymore
2424
$instanceId = session_id();
2525

2626
$resumable = new Resumable($request, $response, $instanceId);
@@ -43,7 +43,7 @@ return match ($status){
4343
## More ##
4444
### Setting custom filename(s) ###
4545

46-
```
46+
```php
4747
// custom filename (extension from original file will be magically removed and re-appended)
4848
$originalName = $resumable->getOriginalFilename(Resumable::WITHOUT_EXTENSION); // will gove you "original Name" instead of "original Name.png"
4949

@@ -62,6 +62,6 @@ if (true === $resumable->isUploadComplete()) { // true when the final file has b
6262
```
6363

6464
## Testing
65-
```
65+
```sh
6666
$ ./vendor/bin/phpunit
6767
```

src/Resumable.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function setResumableOption(array $resumableOption)
7070
$this->resumableOption = array_merge($this->resumableOption, $resumableOption);
7171
}
7272

73-
// sets original filename and extenstion, blah blah
73+
// sets original filename and extension, blah blah
7474
public function preProcess()
7575
{
7676
if (!empty($this->resumableParams())) {
@@ -177,9 +177,9 @@ public function handleTestChunk()
177177
{
178178
$identifier = $this->resumableParam($this->resumableOption['identifier']);
179179
$filename = $this->resumableParam($this->resumableOption['filename']);
180-
$chunkNumber = $this->resumableParam($this->resumableOption['chunkNumber']);
181-
$chunkSize = $this->resumableParam($this->resumableOption['chunkSize']);
182-
$totalChunks = $this->resumableParam($this->resumableOption['totalChunks']);
180+
$chunkNumber = (int) $this->resumableParam($this->resumableOption['chunkNumber']);
181+
$chunkSize = (int) $this->resumableParam($this->resumableOption['chunkSize']);
182+
$totalChunks = (int) $this->resumableParam($this->resumableOption['totalChunks']);
183183

184184
if (!$this->isChunkUploaded($identifier, $filename, $chunkNumber)) {
185185
return $this->response->header(204);
@@ -199,9 +199,9 @@ public function handleChunk()
199199
$file = $this->request->file();
200200
$identifier = $this->resumableParam($this->resumableOption['identifier']);
201201
$filename = $this->resumableParam($this->resumableOption['filename']);
202-
$chunkNumber = $this->resumableParam($this->resumableOption['chunkNumber']);
203-
$chunkSize = $this->resumableParam($this->resumableOption['chunkSize']);
204-
$totalChunks = $this->resumableParam($this->resumableOption['totalChunks']);
202+
$chunkNumber = (int) $this->resumableParam($this->resumableOption['chunkNumber']);
203+
$chunkSize = (int) $this->resumableParam($this->resumableOption['chunkSize']);
204+
$totalChunks = (int) $this->resumableParam($this->resumableOption['totalChunks']);
205205

206206
if (!$this->isChunkUploaded($identifier, $filename, $chunkNumber)) {
207207
$chunkFile = $this->tmpChunkDir($identifier) . DIRECTORY_SEPARATOR . $this->tmpChunkFilename($filename, $chunkNumber);
@@ -243,7 +243,7 @@ private function createFileAndDeleteTmp($identifier, $filename)
243243

244244
if ($this->createFileFromChunks($chunkFiles, $this->filepath) && $this->deleteTmpFolder) {
245245
$tmpFolder->delete();
246-
$this->uploadComplete = true;
246+
$this->isUploadComplete = true;
247247
}
248248
}
249249

@@ -295,14 +295,14 @@ public function tmpChunkDir($identifier)
295295

296296
/**
297297
* make directory if it doesn't exists (Immune against the race condition)
298-
*
299-
*
300-
* since the resuamble is usually used with simultaneously uploads,
301-
* this sometimes resulted in directory creation btween the *is_dir* check
298+
*
299+
*
300+
* since the resumable is usually used with simultaneously uploads,
301+
* this sometimes resulted in directory creation between the *is_dir* check
302302
* and *mkdir* then following race condition.
303303
* in this setup it will shut down the mkdir error
304304
* then try to check if directory is created after that
305-
*
305+
*
306306
* @param string $path the directoryPath to ensure
307307
* @return void
308308
* @throws \Exception
@@ -361,7 +361,7 @@ public function createFileFromChunks($chunkFiles, $destFile)
361361

362362
public function moveUploadedFile($file, $destFile)
363363
{
364-
//workaround cakephp error regarding: TMP not defined
364+
//workaround cakephp error regarding: TMP not defined
365365
define("TMP",sys_get_temp_dir());
366366

367367
$file = new File($file);

0 commit comments

Comments
 (0)