mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-02-17 17:58:40 +00:00
Fixing draw and drafting create
This commit is contained in:
parent
734877e4ec
commit
4ff01c1c6f
|
|
@ -213,18 +213,23 @@ class Controller extends ModuleAbstract implements WebInterface
|
||||||
|
|
||||||
if (!empty($files)) {
|
if (!empty($files)) {
|
||||||
$upload = new UploadFile();
|
$upload = new UploadFile();
|
||||||
$rndPath = str_pad(dechex(rand(0, 65535)), 4, '0', STR_PAD_LEFT);
|
$path = self::createMediaPath($basePath);
|
||||||
$path = '/' . trim($basePath, '/\\.') . '/' . $rndPath[0] . $rndPath[1] . '/' . $rndPath[2] . $rndPath[3];
|
|
||||||
$upload->setOutputDir($path);
|
$upload->setOutputDir($path);
|
||||||
$upload->setFileName(false);
|
$upload->setFileName(false);
|
||||||
|
|
||||||
$status = $upload->upload($files);
|
$status = $upload->upload($files);
|
||||||
$mediaCreated = $this->createDbEntries($status, $account);
|
$mediaCreated = self::createDbEntries($status, $account);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $mediaCreated;
|
return $mediaCreated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function createMediaPath(string $basePath = '/Modules/Media/Files') : string
|
||||||
|
{
|
||||||
|
$rndPath = str_pad(dechex(rand(0, 65535)), 4, '0', STR_PAD_LEFT);
|
||||||
|
return '/' . trim($basePath, '/\\.') . '/' . $rndPath[0] . $rndPath[1] . '/' . $rndPath[2] . $rndPath[3];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $status Files
|
* @param array $status Files
|
||||||
* @param int $account Uploader
|
* @param int $account Uploader
|
||||||
|
|
@ -234,7 +239,7 @@ class Controller extends ModuleAbstract implements WebInterface
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
*/
|
*/
|
||||||
public function createDbEntries(array $status, int $account) : array
|
public static function createDbEntries(array $status, int $account) : array
|
||||||
{
|
{
|
||||||
$mediaCreated = [];
|
$mediaCreated = [];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -138,9 +138,9 @@ class UploadFile
|
||||||
if (!$this->fileName || empty($this->fileName) || file_exists($path . '/' . $this->fileName)) {
|
if (!$this->fileName || empty($this->fileName) || file_exists($path . '/' . $this->fileName)) {
|
||||||
$rnd = '';
|
$rnd = '';
|
||||||
|
|
||||||
|
// todo: implement limit since this could get exploited
|
||||||
do {
|
do {
|
||||||
$sha = sha1_file($f['tmp_name'] . $rnd);
|
$sha = sha1_file($f['tmp_name'] . $rnd);
|
||||||
$sha .= '.' . $extension;
|
|
||||||
|
|
||||||
if ($sha === false) {
|
if ($sha === false) {
|
||||||
$result[$key]['status'] = UploadStatus::FAILED_HASHING;
|
$result[$key]['status'] = UploadStatus::FAILED_HASHING;
|
||||||
|
|
@ -148,6 +148,8 @@ class UploadFile
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$sha .= '.' . $extension;
|
||||||
|
|
||||||
$this->fileName = $sha;
|
$this->fileName = $sha;
|
||||||
$rnd = mt_rand();
|
$rnd = mt_rand();
|
||||||
} while (file_exists($path . '/' . $this->fileName));
|
} while (file_exists($path . '/' . $this->fileName));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user