|
@@ -31,14 +31,16 @@ class Resumable
|
|
|
|
|
|
protected $filename;
|
|
protected $filename;
|
|
|
|
|
|
- protected $originalFilename;
|
|
|
|
-
|
|
|
|
protected $filepath;
|
|
protected $filepath;
|
|
|
|
|
|
protected $extension;
|
|
protected $extension;
|
|
|
|
|
|
|
|
+ protected $originalFilename;
|
|
|
|
+
|
|
protected $isUploadComplete = false;
|
|
protected $isUploadComplete = false;
|
|
|
|
|
|
|
|
+ const WITHOUT_EXTENSION = true;
|
|
|
|
+
|
|
public function __construct(Request $request, Response $response)
|
|
public function __construct(Request $request, Response $response)
|
|
{
|
|
{
|
|
$this->request = $request;
|
|
$this->request = $request;
|
|
@@ -46,6 +48,19 @@ class Resumable
|
|
|
|
|
|
$this->log = new Logger('debug');
|
|
$this->log = new Logger('debug');
|
|
$this->log->pushHandler(new StreamHandler('debug.log', Logger::DEBUG));
|
|
$this->log->pushHandler(new StreamHandler('debug.log', Logger::DEBUG));
|
|
|
|
+
|
|
|
|
+ $this->preProcess();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // sets original filename and extenstion, blah blah
|
|
|
|
+ public function preProcess()
|
|
|
|
+ {
|
|
|
|
+ if (!empty($this->resumableParams())) {
|
|
|
|
+ if (!empty($this->request->file())) {
|
|
|
|
+ $this->extension = $this->findExtension($this->resumableParam('filename'));
|
|
|
|
+ $this->originalFilename = $this->resumableParam('filename');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
public function process()
|
|
public function process()
|
|
@@ -96,9 +111,13 @@ class Resumable
|
|
*
|
|
*
|
|
* @return string Final filename
|
|
* @return string Final filename
|
|
*/
|
|
*/
|
|
- public function getOriginalFilename()
|
|
|
|
|
|
+ public function getOriginalFilename($withoutExtension = false)
|
|
{
|
|
{
|
|
- return $this->originalFilename;
|
|
|
|
|
|
+ if ($withoutExtension === static::WITHOUT_EXTENSION) {
|
|
|
|
+ return $this->removeExtension($this->originalFilename);
|
|
|
|
+ } else {
|
|
|
|
+ return $this->originalFilename;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -148,7 +167,7 @@ class Resumable
|
|
return $this->response->header(200);
|
|
return $this->response->header(200);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public function handleChunk()
|
|
public function handleChunk()
|
|
{
|
|
{
|
|
$file = $this->request->file();
|
|
$file = $this->request->file();
|
|
@@ -173,23 +192,21 @@ class Resumable
|
|
|
|
|
|
/**
|
|
/**
|
|
* Create the final file from chunks
|
|
* Create the final file from chunks
|
|
- *
|
|
|
|
*/
|
|
*/
|
|
private function createFileAndDeleteTmp($identifier, $filename)
|
|
private function createFileAndDeleteTmp($identifier, $filename)
|
|
{
|
|
{
|
|
$tmpFolder = new Folder($this->tmpChunkDir($identifier));
|
|
$tmpFolder = new Folder($this->tmpChunkDir($identifier));
|
|
$chunkFiles = $tmpFolder->read(true, true, true)[1];
|
|
$chunkFiles = $tmpFolder->read(true, true, true)[1];
|
|
|
|
|
|
- // save original filename
|
|
|
|
- $this->originalFilename = $filename;
|
|
|
|
-
|
|
|
|
- // if the user has set a filename (or decided to slugify it), change the final filename
|
|
|
|
|
|
+ // if the user has set a custom filename
|
|
if (null !== $this->filename) {
|
|
if (null !== $this->filename) {
|
|
- $this->filename = $this->createSafeFilename($this->filename, $filename);
|
|
|
|
|
|
+ $finalFilename = $this->createSafeFilename($this->filename, $filename);
|
|
|
|
+ } else {
|
|
|
|
+ $finalFilename = $filename;
|
|
}
|
|
}
|
|
|
|
|
|
// replace filename reference by the final file
|
|
// replace filename reference by the final file
|
|
- $this->filepath = $this->uploadFolder . DIRECTORY_SEPARATOR . $this->filename;
|
|
|
|
|
|
+ $this->filepath = $this->uploadFolder . DIRECTORY_SEPARATOR . $finalFilename;
|
|
$this->extension = $this->findExtension($this->filepath);
|
|
$this->extension = $this->findExtension($this->filepath);
|
|
|
|
|
|
if ($this->createFileFromChunks($chunkFiles, $this->filepath) && $this->deleteTmpFolder) {
|
|
if ($this->createFileFromChunks($chunkFiles, $this->filepath) && $this->deleteTmpFolder) {
|