mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-02-11 06:58:41 +00:00
Fixing upload bugs
This commit is contained in:
parent
4557f2a0f8
commit
537b9291ab
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@
|
|||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
request.send();
|
||||
};
|
||||
}(window.jsOMS = window.jsOMS || {}));
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ echo $this->getData('nav')->render(); ?>
|
|||
<section class="box w-50">
|
||||
<header><h1><?= $this->l11n->lang['Media']['Upload']; ?></h1></header>
|
||||
<div class="inner">
|
||||
<form method="POST" action="<?= \phpOMS\Uri\UriFactory::build('/{/lang}/api/media/create'); ?>">
|
||||
<form method="POST" id="media-uploader" action="<?= \phpOMS\Uri\UriFactory::build('/{/lang}/api/media'); ?>">
|
||||
<table class="layout wf-100">
|
||||
<tr><td><label for="iName"><?= $this->l11n->lang['Media']['Name']; ?></label>
|
||||
<tr><td><input type="text" id="iName" name="name" placeholder="">
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
|||
<section class="box w-100">
|
||||
<header><h1><?= $media->getName() ?></h1></header>
|
||||
<div class="inner">
|
||||
<table class="list w-100">
|
||||
<tbody>
|
||||
<tr><td>Size<td class="wf-100"><?= $media->getSize(); ?>
|
||||
<tr><td>Created at<td><?= $media->getCreatedAt()->format('Y-m-d'); ?>
|
||||
<tr><td>Created by<td><?= $media->getCreatedBy(); ?>
|
||||
<tr><td>Description<td><?= $media->getDescription(); ?>
|
||||
<tr><td colspan="2">Content
|
||||
</table>
|
||||
<?php if(in_array($media->getExtension(), ['gif', 'bmp', 'jpg', 'jpeg', 'png'])) : ?>
|
||||
<img src="<?= $media->getPath(); ?>">
|
||||
<img src="<?= $this->request->getUri()->getBase() . $media->getPath(); ?>">
|
||||
<?php else : ?>
|
||||
<pre><?= htmlspecialchars(file_get_contents(ROOT_PATH . '/' . $media->getPath())); ?></pre>
|
||||
<pre>
|
||||
<?php
|
||||
$output = htmlspecialchars(file_get_contents(ROOT_PATH . '/' . $media->getPath()));
|
||||
$output = str_replace(["\r\n", "\r"], "\n", $output);
|
||||
$output = explode("\n", $output);
|
||||
foreach($output as $line) : ?><span><?= $line; ?></span><?php endforeach; ?>
|
||||
</pre>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</section>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user