Skip to content

Commit

Permalink
Merge pull request #38 from code-lts/bugfixes
Browse files Browse the repository at this point in the history
Some bugfixes from my fork
  • Loading branch information
dilab authored Dec 17, 2023
2 parents d7a4f11 + 658e854 commit 62c3fff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ To install, use composer:
## How to use
**upload.php**

```
```php
<?php
include 'vendor/autoload.php';

Expand All @@ -20,7 +20,7 @@ use Dilab\Resumable;

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

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

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

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

## Testing
```
```sh
$ ./vendor/bin/phpunit
```
28 changes: 14 additions & 14 deletions src/Resumable.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function setResumableOption(array $resumableOption)
$this->resumableOption = array_merge($this->resumableOption, $resumableOption);
}

// sets original filename and extenstion, blah blah
// sets original filename and extension, blah blah
public function preProcess()
{
if (!empty($this->resumableParams())) {
Expand Down Expand Up @@ -177,9 +177,9 @@ public function handleTestChunk()
{
$identifier = $this->resumableParam($this->resumableOption['identifier']);
$filename = $this->resumableParam($this->resumableOption['filename']);
$chunkNumber = $this->resumableParam($this->resumableOption['chunkNumber']);
$chunkSize = $this->resumableParam($this->resumableOption['chunkSize']);
$totalChunks = $this->resumableParam($this->resumableOption['totalChunks']);
$chunkNumber = (int) $this->resumableParam($this->resumableOption['chunkNumber']);
$chunkSize = (int) $this->resumableParam($this->resumableOption['chunkSize']);
$totalChunks = (int) $this->resumableParam($this->resumableOption['totalChunks']);

if (!$this->isChunkUploaded($identifier, $filename, $chunkNumber)) {
return $this->response->header(204);
Expand All @@ -199,9 +199,9 @@ public function handleChunk()
$file = $this->request->file();
$identifier = $this->resumableParam($this->resumableOption['identifier']);
$filename = $this->resumableParam($this->resumableOption['filename']);
$chunkNumber = $this->resumableParam($this->resumableOption['chunkNumber']);
$chunkSize = $this->resumableParam($this->resumableOption['chunkSize']);
$totalChunks = $this->resumableParam($this->resumableOption['totalChunks']);
$chunkNumber = (int) $this->resumableParam($this->resumableOption['chunkNumber']);
$chunkSize = (int) $this->resumableParam($this->resumableOption['chunkSize']);
$totalChunks = (int) $this->resumableParam($this->resumableOption['totalChunks']);

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

if ($this->createFileFromChunks($chunkFiles, $this->filepath) && $this->deleteTmpFolder) {
$tmpFolder->delete();
$this->uploadComplete = true;
$this->isUploadComplete = true;
}
}

Expand Down Expand Up @@ -295,14 +295,14 @@ public function tmpChunkDir($identifier)

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

public function moveUploadedFile($file, $destFile)
{
//workaround cakephp error regarding: TMP not defined
//workaround cakephp error regarding: TMP not defined
define("TMP",sys_get_temp_dir());

$file = new File($file);
Expand Down

0 comments on commit 62c3fff

Please sign in to comment.