mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-02-12 07:18:41 +00:00
Fix relative path
This commit is contained in:
parent
e4c0255dfb
commit
39325e502a
|
|
@ -16,6 +16,8 @@ namespace Modules\Media\Controller;
|
|||
|
||||
use Modules\Media\Models\Media;
|
||||
use Modules\Media\Models\MediaMapper;
|
||||
use Modules\Media\Models\Collection;
|
||||
use Modules\Media\Models\CollectionMapper;
|
||||
use Modules\Media\Models\UploadFile;
|
||||
use Modules\Media\Models\UploadStatus;
|
||||
|
||||
|
|
@ -73,8 +75,9 @@ final class ApiController extends Controller
|
|||
*/
|
||||
public function apiMediaUpload(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
||||
{
|
||||
// todo: handle logging
|
||||
// todo: this is really messy because i don't use formdata object. media first get's uploaded but nothing is done with the form data
|
||||
$uploads = $this->uploadFiles(
|
||||
$request->getData('name') ?? '',
|
||||
$request->getFiles(),
|
||||
$request->getHeader()->getAccount(),
|
||||
(string) ($request->getData('path') ?? __DIR__ . '/../../../Modules/Media/Files')
|
||||
|
|
@ -107,6 +110,7 @@ final class ApiController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $name Name
|
||||
* @param array $files Files
|
||||
* @param int $account Uploader
|
||||
* @param string $basePath Base path
|
||||
|
|
@ -115,7 +119,7 @@ final class ApiController extends Controller
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function uploadFiles(array $files, int $account, string $basePath = 'Modules/Media/Files') : array
|
||||
public function uploadFiles(string $name, array $files, int $account, string $basePath = 'Modules/Media/Files') : array
|
||||
{
|
||||
$mediaCreated = [];
|
||||
|
||||
|
|
@ -123,8 +127,8 @@ final class ApiController extends Controller
|
|||
$upload = new UploadFile();
|
||||
$upload->setOutputDir(self::createMediaPath($basePath));
|
||||
|
||||
$status = $upload->upload($files);
|
||||
$mediaCreated = self::createDbEntries($status, $account);
|
||||
$status = $upload->upload($files, $name);
|
||||
$mediaCreated = self::createDbEntries($name, $status, $account);
|
||||
}
|
||||
|
||||
return $mediaCreated;
|
||||
|
|
@ -144,7 +148,7 @@ final class ApiController extends Controller
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function createDbEntries(array $status, int $account) : array
|
||||
public static function createDbEntries(string $name, array $status, int $account) : array
|
||||
{
|
||||
$mediaCreated = [];
|
||||
|
||||
|
|
@ -178,7 +182,7 @@ final class ApiController extends Controller
|
|||
|
||||
private static function normalizeDbPath(string $path) : string
|
||||
{
|
||||
$realpath = \realpath(__DIR__ . '/../../');
|
||||
$realpath = \realpath(__DIR__ . '/../../../');
|
||||
|
||||
if ($realpath === false) {
|
||||
throw new \Exception();
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ class UploadFile
|
|||
* Upload file to server.
|
||||
*
|
||||
* @param array $files File data ($_FILE)
|
||||
* @param string $name File name
|
||||
* @param string $encoding Encoding used for uploaded file. Empty string will not convert file content.
|
||||
*
|
||||
* @return array
|
||||
|
|
@ -96,7 +97,7 @@ class UploadFile
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function upload(array $files, string $encoding = 'UTF-8') : array
|
||||
public function upload(array $files, string $name = '', string $encoding = 'UTF-8') : array
|
||||
{
|
||||
$result = [];
|
||||
|
||||
|
|
@ -141,7 +142,7 @@ class UploadFile
|
|||
}
|
||||
|
||||
$split = \explode('.', $f['name']);
|
||||
$result[$key]['name'] = $split[0];
|
||||
$result[$key]['name'] = \count($files) === 1 && !empty($name) ? $name : $split[0];
|
||||
$extension = \count($split) > 1 ? $split[\count($split) - 1] : '';
|
||||
$result[$key]['extension'] = $extension;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
<td><?= $this->getHtml('Created', 'Media') ?>
|
||||
<tfoot>
|
||||
<tbody>
|
||||
<?php $count = 0; foreach ($this->media as $key => $value) : $count++;
|
||||
<?php $count = 0; foreach ($this->media as $key => $value) : ++$count;
|
||||
$url = \phpOMS\Uri\UriFactory::build('{/lang}/backend/media/single?{?}&id=' . $value->getId());
|
||||
|
||||
$icon = '';
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
<input autocomplete="off" class="input" id="mediaInput" name="mediaFile" type="text"
|
||||
data-emptyAfter="true"
|
||||
data-autocomplete="false"
|
||||
data-src="http://127.0.0.1/en/api/media/find?search={#mediaInput}">
|
||||
data-src="{/lang}/api/media/find?search={#mediaInput}">
|
||||
<div id="iMediaInput-dropdown" class="dropdown" data-active="true">
|
||||
<table id="a1" class="table darkred">
|
||||
<thead>
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ echo $this->getData('nav')->render(); ?>
|
|||
<tbody>
|
||||
<?php $count = 0;
|
||||
foreach ($media as $key => $value) :
|
||||
$count++;
|
||||
++$count;
|
||||
$url = \phpOMS\Uri\UriFactory::build('{/lang}/backend/media/single?{?}&id=' . $value->getId());
|
||||
$icon = $fileIconFunction(\phpOMS\System\File\FileUtils::getExtensionType($value->getExtension()));
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -36,7 +36,8 @@ echo $this->getData('nav')->render();
|
|||
<tr><td><?= $this->getHtml('Size') ?><td class="wf-100"><?= $this->printHtml($media->getSize()); ?>
|
||||
<tr><td><?= $this->getHtml('Created') ?><td><?= $this->printHtml($media->getCreatedAt()->format('Y-m-d')); ?>
|
||||
<tr><td><?= $this->getHtml('Creator') ?><td><?= $this->printHtml($media->getCreatedBy()->getName1()); ?>
|
||||
<tr><td><?= $this->getHtml('Description') ?><td><?= $this->printHtml($media->getDescription()); ?>
|
||||
<tr><td colspan="2"><?= $this->getHtml('Description') ?>
|
||||
<tr><td colspan="2"><?= $media->getDescription(); ?>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
|
|
@ -59,7 +60,7 @@ echo $this->getData('nav')->render();
|
|||
<td><?= $this->getHtml('Created') ?>
|
||||
<tbody>
|
||||
<?php
|
||||
if (!\is_dir($media->isAbsolute() ? $path : __DIR__ . '/../../../' . \ltrim($media->getPath(), '//'))
|
||||
if (!\is_dir($media->isAbsolute() ? $path : __DIR__ . '/../../../../' . \ltrim($media->getPath(), '//'))
|
||||
|| $media->getPath() === ''
|
||||
) :
|
||||
foreach ($media as $key => $value) :
|
||||
|
|
@ -104,12 +105,12 @@ echo $this->getData('nav')->render();
|
|||
<?php else : ?>
|
||||
<button class="floatRight">Edit</button>
|
||||
|
||||
<?php if (!\file_exists($media->isAbsolute() ? $path : __DIR__ . '/../../../' . \ltrim($path, '/'))) : ?>
|
||||
<?php if (!\file_exists($media->isAbsolute() ? $path : __DIR__ . '/../../../../' . \ltrim($path, '/'))) : ?>
|
||||
<div class="centerText"><i class="fa fa-question fa-5x"></i></div>
|
||||
<?php else : ?>
|
||||
<pre>
|
||||
<?php
|
||||
$output = $this->lineContentFunction($media->isAbsolute() ? $path : __DIR__ . '/../../../' . \ltrim($path, '/'));
|
||||
$output = $this->lineContentFunction($media->isAbsolute() ? $path : __DIR__ . '/../../../../' . \ltrim($path, '/'));
|
||||
foreach ($output as $line) : ?><span><?= $this->printHtml($line); ?></span><?php endforeach; ?>
|
||||
</pre>
|
||||
<?php endif; ?>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user