diff --git a/config/chunk-upload.php b/config/chunk-upload.php index 422fa78..4b0ad40 100644 --- a/config/chunk-upload.php +++ b/config/chunk-upload.php @@ -30,6 +30,7 @@ 'use' => [ 'session' => true, // should the chunk name use the session id? The uploader must send cookie!, 'browser' => false, // instead of session we can use the ip and browser? + 'hashName' => false // use a hash name instead of the original file name ], ], ], diff --git a/src/Commands/ClearChunksCommand.php b/src/Commands/ClearChunksCommand.php index 5956297..05a0aee 100644 --- a/src/Commands/ClearChunksCommand.php +++ b/src/Commands/ClearChunksCommand.php @@ -6,6 +6,7 @@ use Illuminate\Support\Str; use Pion\Laravel\ChunkUpload\ChunkFile; use Pion\Laravel\ChunkUpload\Storage\ChunkStorage; +use RuntimeException; use Symfony\Component\Console\Output\OutputInterface; class ClearChunksCommand extends Command @@ -51,9 +52,13 @@ public function handle(ChunkStorage $storage) $this->comment('> '.$file, $verbouse); // delete the file - if ($file->delete()) { - ++$deleted; - } else { + try{ + if ($file->delete()) { + ++$deleted; + } else { + $this->error('> chunk not deleted: '.$file); + } + }catch(RuntimeException $err){ $this->error('> chunk not deleted: '.$file); } } diff --git a/src/Config/AbstractConfig.php b/src/Config/AbstractConfig.php index bb89fd1..12eddbf 100644 --- a/src/Config/AbstractConfig.php +++ b/src/Config/AbstractConfig.php @@ -64,4 +64,11 @@ abstract public function chunkUseSessionForName(); * @return bool */ abstract public function chunkUseBrowserInfoForName(); + + /** + * Should the chunk name add a hash name instead of original file name? + * + * @return bool + */ + abstract public function chunkUseHashNameForName(); } diff --git a/src/Config/FileConfig.php b/src/Config/FileConfig.php index 02a0043..b97c2ee 100644 --- a/src/Config/FileConfig.php +++ b/src/Config/FileConfig.php @@ -88,6 +88,16 @@ public function chunkUseBrowserInfoForName() return $this->get('chunk.name.use.browser', false); } + /** + * Should the chunk name add a hash name instead of original file name? + * + * @return bool + */ + public function chunkUseHashNameForName() + { + return $this->get('chunk.name.use.hashName', false); + } + /** * Returns a chunks config value. * diff --git a/src/Handler/AbstractHandler.php b/src/Handler/AbstractHandler.php index d5a523a..abf10f5 100644 --- a/src/Handler/AbstractHandler.php +++ b/src/Handler/AbstractHandler.php @@ -92,7 +92,7 @@ public function createChunkFileName($additionalName = null, $currentChunkIndex = { // prepare basic name structure $array = [ - $this->file->getClientOriginalName(), + $this->config->chunkUseHashNameForName() ? md5($this->file->getClientOriginalName()) : $this->file->getClientOriginalName(), ]; // ensure that the chunk name is for unique for the client session