From 537b9291abd771f000336c411ab3804ef56d92c6 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 25 May 2016 22:52:49 +0200 Subject: [PATCH] Fixing upload bugs --- Controller.php | 3 ++- Models/Upload.js | 1 + Models/UploadFile.php | 20 ++++++++++---------- Theme/backend/media-create.tpl.php | 2 +- Theme/backend/media-list.tpl.php | 4 +--- Theme/backend/media-single.tpl.php | 21 +++++++++++++++++++-- 6 files changed, 34 insertions(+), 17 deletions(-) diff --git a/Controller.php b/Controller.php index b14c2df..41bfdde 100644 --- a/Controller.php +++ b/Controller.php @@ -214,6 +214,7 @@ class Controller extends ModuleAbstract implements WebInterface $path = '/Modules/Media/Files/' . $rndPath[0] . $rndPath[1] . '/' . $rndPath[2] . $rndPath[3]; $upload->setOutputDir($path); $upload->setFileName(false); + $status = $upload->upload($files); $mediaCreated = $this->createDbEntries($status, $account); } @@ -237,7 +238,7 @@ class Controller extends ModuleAbstract implements WebInterface foreach ($status as $uFile) { if ($uFile['status'] === UploadStatus::OK) { $media = new Media(); - $media->setPath($uFile['path'] . '/' . $uFile['filename']); + $media->setPath(trim($uFile['path'], '/') . '/' . $uFile['filename']); $media->setName($uFile['filename']); $media->setSize($uFile['size']); $media->setCreatedBy($account); diff --git a/Models/Upload.js b/Models/Upload.js index 174eddb..4933d8a 100644 --- a/Models/Upload.js +++ b/Models/Upload.js @@ -95,6 +95,7 @@ return false; } }); + request.send(); }; }(window.jsOMS = window.jsOMS || {})); diff --git a/Models/UploadFile.php b/Models/UploadFile.php index 724e389..3077dad 100644 --- a/Models/UploadFile.php +++ b/Models/UploadFile.php @@ -15,6 +15,8 @@ */ namespace Modules\Media\Models; +use phpOMS\System\File\Directory; + /** * Upload. @@ -89,7 +91,7 @@ class UploadFile } $this->findOutputDir($files); - $rpath = $this->outputDir; + $path = ROOT_PATH . $this->outputDir; foreach ($files as $key => $f) { $result[$key] = []; @@ -116,15 +118,13 @@ class UploadFile } // TODO: do I need pecl fileinfo? - if (!empty($this->allowedTypes) && false === $ext = array_search($f['type'], $this->allowedTypes, true)) { + if (!empty($this->allowedTypes) && ($ext = array_search($f['type'], $this->allowedTypes, true)) === false) { // wrong file format $result[$key]['status'] = UploadStatus::WRONG_EXTENSION; return $result; } - $path = __DIR__ . '/../../..' . $this->outputDir; - if ($this->preserveFileName) { $this->fileName = $f['name']; } @@ -133,6 +133,8 @@ class UploadFile $extension = count($split) > 1 ? $split[count($split) - 1] : ''; $result[$key]['extension'] = $extension; + // ! and empty same?! + $result[$key]['filename'] = $this->fileName; if (!$this->fileName || empty($this->fileName) || file_exists($path . '/' . $this->fileName)) { $rnd = ''; @@ -147,14 +149,12 @@ class UploadFile } $this->fileName = $sha; - $rnd = rand(); + $rnd = mt_rand(); } while (file_exists($path . '/' . $this->fileName)); } - $result[$key]['filename'] = $this->fileName; - if (!is_dir($path)) { - \mkdir($path, '0655', true); + Directory::createPath($path, '0655', true); } if (!is_uploaded_file($f['tmp_name'])) { @@ -169,7 +169,7 @@ class UploadFile return $result; } - $result[$key]['path'] = $rpath; + $result[$key]['path'] = $this->outputDir; } return $result; @@ -192,7 +192,7 @@ class UploadFile $rndPath = str_pad(dechex(rand(0, 65535)), 4, '0', STR_PAD_LEFT); } while (file_exists($this->outputDir . '/' . $rndPath)); - $this->outputDir = $this->outputDir . '/' . $rndPath; + $this->outputDir = '/../../..' . $this->outputDir . '/' . $rndPath; } } diff --git a/Theme/backend/media-create.tpl.php b/Theme/backend/media-create.tpl.php index 8dd0cee..1608b77 100644 --- a/Theme/backend/media-create.tpl.php +++ b/Theme/backend/media-create.tpl.php @@ -21,7 +21,7 @@ echo $this->getData('nav')->render(); ?>

l11n->lang['Media']['Upload']; ?>

-
+
diff --git a/Theme/backend/media-list.tpl.php b/Theme/backend/media-list.tpl.php index c0f3430..14e6c93 100644 --- a/Theme/backend/media-list.tpl.php +++ b/Theme/backend/media-list.tpl.php @@ -17,9 +17,7 @@ * @var \phpOMS\Views\View $this */ -$mediaMapper = new \Modules\Media\Models\MediaMapper($this->app->dbPool->get()); -$media = $mediaMapper->getNewest(25); - +$media = \Modules\Media\Models\MediaMapper::getNewest(25); $footerView = new \Web\Views\Lists\PaginationView($this->app, $this->request, $this->response); $footerView->setTemplate('/Web/Templates/Lists/Footer/PaginationBig'); $footerView->setPages(count($media) / 25); diff --git a/Theme/backend/media-single.tpl.php b/Theme/backend/media-single.tpl.php index 81c7275..f03ce73 100644 --- a/Theme/backend/media-single.tpl.php +++ b/Theme/backend/media-single.tpl.php @@ -16,6 +16,9 @@ /** * @var \phpOMS\Views\View $this */ +/** + * @var $media \Modules\Media\Models\Media + */ $media = $this->getData('media'); echo $this->getData('nav')->render(); ?> @@ -23,10 +26,24 @@ echo $this->getData('nav')->render();

getName() ?>

+ + +
SizegetSize(); ?> +
Created atgetCreatedAt()->format('Y-m-d'); ?> +
Created bygetCreatedBy(); ?> +
DescriptiongetDescription(); ?> +
Content +
getExtension(), ['gif', 'bmp', 'jpg', 'jpeg', 'png'])) : ?> - + -
getPath())); ?>
+
+            getPath()));
+            $output = str_replace(["\r\n", "\r"], "\n", $output);
+            $output = explode("\n", $output);
+            foreach($output as $line) : ?>
+