mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-01-29 17:18:39 +00:00
change uploader
This commit is contained in:
parent
b0833bebc4
commit
3640dfd596
|
|
@ -165,7 +165,7 @@ final class ApiController extends Controller
|
|||
}
|
||||
|
||||
$upload = new UploadFile();
|
||||
$upload->setOutputDir($outputDir);
|
||||
$upload->outputDir = $outputDir;
|
||||
|
||||
$status = $upload->upload($files, $name, $absolute, $encryptionKey);
|
||||
|
||||
|
|
@ -178,7 +178,7 @@ final class ApiController extends Controller
|
|||
string $path = '',
|
||||
) : array {
|
||||
$upload = new UploadFile();
|
||||
$upload->setOutputDir($path);
|
||||
$upload->outputDir = $path;
|
||||
|
||||
$status = $upload->upload($files, $name, true, '');
|
||||
|
||||
|
|
|
|||
|
|
@ -261,7 +261,7 @@ class Media implements \JsonSerializable
|
|||
*/
|
||||
public function setPassword(?string $password) : void
|
||||
{
|
||||
$temp = $password === null ? null : \password_hash($password, \PASSWORD_DEFAULT);
|
||||
$temp = $password === null ? null : \password_hash($password, \PASSWORD_BCRYPT);
|
||||
|
||||
$this->password = $temp === false ? null : $temp;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class UploadFile
|
|||
* @var bool
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private bool $isInterlaced = true;
|
||||
public bool $isInterlaced = true;
|
||||
|
||||
/**
|
||||
* Upload max size.
|
||||
|
|
@ -53,7 +53,7 @@ class UploadFile
|
|||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private int $maxSize = 50000000;
|
||||
public int $maxSize = 50000000;
|
||||
|
||||
/**
|
||||
* Allowed mime types.
|
||||
|
|
@ -69,15 +69,7 @@ class UploadFile
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private string $outputDir = __DIR__ . '/../../Modules/Media/Files';
|
||||
|
||||
/**
|
||||
* Output file name.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private string $fileName = '';
|
||||
public string $outputDir = __DIR__ . '/../../Modules/Media/Files';
|
||||
|
||||
/**
|
||||
* Output file name.
|
||||
|
|
@ -85,7 +77,7 @@ class UploadFile
|
|||
* @var bool
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private bool $preserveFileName = true;
|
||||
public bool $preserveFileName = true;
|
||||
|
||||
/**
|
||||
* Upload file to server.
|
||||
|
|
@ -153,8 +145,8 @@ class UploadFile
|
|||
return $result;
|
||||
}
|
||||
|
||||
$split = \explode('.', $f['name']);
|
||||
$result[$key]['name'] = \count($files) === 1 && !empty($name)
|
||||
$split = \explode('.', $f['name']);
|
||||
$result[$key]['filename'] = \count($files) === 1 && !empty($name)
|
||||
? $name
|
||||
: $f['name'];
|
||||
|
||||
|
|
@ -162,14 +154,14 @@ class UploadFile
|
|||
$result[$key]['extension'] = $extension;
|
||||
|
||||
if ($this->preserveFileName) {
|
||||
$this->fileName = $f['name'];
|
||||
$result[$key]['filename'] = $this->fileName;
|
||||
$name = $f['name'];
|
||||
$result[$key]['filename'] = $name;
|
||||
}
|
||||
|
||||
if (empty($this->fileName) || \is_file($path . '/' . $this->fileName)) {
|
||||
if (empty($name) || \is_file($path . '/' . $name)) {
|
||||
try {
|
||||
$this->fileName = $this->createFileName($path, $f['tmp_name'], $extension);
|
||||
$result[$key]['filename'] = $this->fileName;
|
||||
$name = $this->createFileName($path, $f['tmp_name'], $extension);
|
||||
$result[$key]['filename'] = $name;
|
||||
} catch (\Exception $e) {
|
||||
$result[$key]['filename'] = $f['name'];
|
||||
$result[$key]['status'] = UploadStatus::FAILED_HASHING;
|
||||
|
|
@ -186,7 +178,7 @@ class UploadFile
|
|||
}
|
||||
}
|
||||
|
||||
if (!\rename($f['tmp_name'], $dest = $path . '/' . $this->fileName)) {
|
||||
if (!\rename($f['tmp_name'], $dest = $path . '/' . $name)) {
|
||||
$result[$key]['status'] = UploadStatus::NOT_MOVABLE;
|
||||
|
||||
return $result;
|
||||
|
|
@ -349,40 +341,6 @@ class UploadFile
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getMaxSize() : int
|
||||
{
|
||||
return $this->maxSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $isInterlaced Is interlaced
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setInterlaced(bool $isInterlaced) : void
|
||||
{
|
||||
$this->isInterlaced = $isInterlaced;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $maxSize Max allowed file size
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setMaxSize(int $maxSize) : void
|
||||
{
|
||||
$this->maxSize = $maxSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*
|
||||
|
|
@ -416,66 +374,4 @@ class UploadFile
|
|||
{
|
||||
$this->allowedTypes[] = $allowedTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getOutputDir() : string
|
||||
{
|
||||
return $this->outputDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define output directory of the upload
|
||||
*
|
||||
* @param string $outputDir Output directory of the uploaded file
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setOutputDir(string $outputDir) : void
|
||||
{
|
||||
$this->outputDir = $outputDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getFileName() : string
|
||||
{
|
||||
return $this->fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the file name of the uploaded file
|
||||
*
|
||||
* @param string $fileName File name of the uploaded file
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setFileName(string $fileName) : void
|
||||
{
|
||||
$this->fileName = $fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define if the uploaded file name should be the same file name as the original file
|
||||
*
|
||||
* @param bool $preserveFileName Keep file name of the original file
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setPreserveFileName(bool $preserveFileName) : void
|
||||
{
|
||||
$this->preserveFileName = $preserveFileName;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,17 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 8.0
|
||||
*
|
||||
* @package Modules\Media
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use phpOMS\System\File\FileUtils;
|
||||
use phpOMS\Uri\UriFactory;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,14 +20,13 @@ include __DIR__ . '/template-functions.php';
|
|||
|
||||
/**
|
||||
* @var \phpOMS\Views\View $this
|
||||
* @var string $parent
|
||||
*/
|
||||
$mediaPath = \urldecode($this->getData('path') ?? '/');
|
||||
|
||||
/**
|
||||
* @var \Modules\Media\Models\Media[] $media
|
||||
*/
|
||||
$media = $this->getData('media');
|
||||
/** @var \Modules\Media\Models\Media[] $media */
|
||||
$media = $this->getData('media') ?? [];
|
||||
|
||||
/** @var \Modules\Admin\Models\Account $account */
|
||||
$account = $this->getData('account');
|
||||
|
||||
$accountDir = $account->getId() . ' ' . $account->login;
|
||||
|
|
@ -193,7 +192,7 @@ $next = empty($media) ? '{/prefix}media/list' : '{/prefix}media/list?{?}&id=
|
|||
</a>
|
||||
<td data-label="<?= $this->getHtml('Tag'); ?>"><?php $tags = $value->getTags(); foreach ($tags as $tag) : ?>
|
||||
<a href="<?= $url; ?>">
|
||||
<span class="tag" style="background: <?= $this->printHtml($tag->color); ?>"><?= $tag->icon !== null ? '<i class="' . $this->printHtml($tag->icon ?? '') . '"></i>' : ''; ?><?= $this->printHtml($tag->getTitle()); ?></span>
|
||||
<span class="tag" style="background: <?= $this->printHtml($tag->color); ?>"><?= $tag->icon !== null ? '<i class="' . $this->printHtml($tag->icon ?? '') . '"></i>' : ''; ?><?= $this->printHtml($tag->getL11n()); ?></span>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
<td data-label="<?= $this->getHtml('Extension'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->extension); ?></a>
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ echo $this->getData('nav')->render();
|
|||
); ?></a>
|
||||
<tr><td><?= $this->getHtml('Tags'); ?><td>
|
||||
<?php foreach ($tags as $tag) : ?>
|
||||
<span class="tag" style="background: <?= $this->printHtml($tag->color); ?>"><?= $tag->icon !== null ? '<i class="' . $this->printHtml($tag->icon ?? '') . '"></i>' : ''; ?><?= $this->printHtml($tag->getTitle()); ?></span>
|
||||
<span class="tag" style="background: <?= $this->printHtml($tag->color); ?>"><?= $tag->icon !== null ? '<i class="' . $this->printHtml($tag->icon ?? '') . '"></i>' : ''; ?><?= $this->printHtml($tag->getL11n()); ?></span>
|
||||
<?php endforeach; ?>
|
||||
<tr><td colspan="2"><?= $this->getHtml('Description'); ?>
|
||||
<tr><td colspan="2"><?= $media->description; ?>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user