mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-02-16 01:08:41 +00:00
log invaid upload permission/file
This commit is contained in:
parent
4ff9b1f93e
commit
d211936a37
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Orange Management
|
* Orange Management
|
||||||
*
|
*
|
||||||
|
|
@ -10,12 +11,13 @@
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
* @link https://orange-management.org
|
* @link https://orange-management.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Modules\Media\Models;
|
namespace Modules\Media\Models;
|
||||||
|
|
||||||
use phpOMS\System\File\FileUtils;
|
|
||||||
use phpOMS\System\File\Local\Directory;
|
use phpOMS\System\File\Local\Directory;
|
||||||
|
use phpOMS\Log\FileLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upload.
|
* Upload.
|
||||||
|
|
@ -105,7 +107,7 @@ class UploadFile
|
||||||
bool $absolute = false,
|
bool $absolute = false,
|
||||||
string $encryptionKey = '',
|
string $encryptionKey = '',
|
||||||
string $encoding = 'UTF-8'
|
string $encoding = 'UTF-8'
|
||||||
) : array {
|
): array {
|
||||||
$result = [];
|
$result = [];
|
||||||
|
|
||||||
if (\count($files) === \count($files, \COUNT_RECURSIVE)) {
|
if (\count($files) === \count($files, \COUNT_RECURSIVE)) {
|
||||||
|
|
@ -169,7 +171,11 @@ class UploadFile
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!\is_dir($path)) {
|
if (!\is_dir($path)) {
|
||||||
Directory::create($path, 0755, true);
|
$created = Directory::create($path, 0755, true);
|
||||||
|
|
||||||
|
if (!$created) {
|
||||||
|
FileLogger::getInstance()->error('Couldn\t upload media file. There maybe is a problem with your permission or uploaded file.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!\rename($f['tmp_name'], $dest = $path . '/' . $this->fileName)) {
|
if (!\rename($f['tmp_name'], $dest = $path . '/' . $this->fileName)) {
|
||||||
|
|
@ -249,7 +255,7 @@ class UploadFile
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private function createFileName(string $path, string $tempName, string $extension) : string
|
private function createFileName(string $path, string $tempName, string $extension): string
|
||||||
{
|
{
|
||||||
$rnd = '';
|
$rnd = '';
|
||||||
$limit = 0;
|
$limit = 0;
|
||||||
|
|
@ -284,7 +290,7 @@ class UploadFile
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private function interlace(string $extension, string $path) : void
|
private function interlace(string $extension, string $path): void
|
||||||
{
|
{
|
||||||
if ($extension === 'png') {
|
if ($extension === 'png') {
|
||||||
$img = \imagecreatefrompng($path);
|
$img = \imagecreatefrompng($path);
|
||||||
|
|
@ -318,7 +324,7 @@ class UploadFile
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private function findOutputDir() : string
|
private function findOutputDir(): string
|
||||||
{
|
{
|
||||||
do {
|
do {
|
||||||
$rndPath = \str_pad(\dechex(\mt_rand(0, 65535)), 4, '0', \STR_PAD_LEFT);
|
$rndPath = \str_pad(\dechex(\mt_rand(0, 65535)), 4, '0', \STR_PAD_LEFT);
|
||||||
|
|
@ -336,7 +342,7 @@ class UploadFile
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private function getUploadError($error) : int
|
private function getUploadError($error): int
|
||||||
{
|
{
|
||||||
switch ($error) {
|
switch ($error) {
|
||||||
case \UPLOAD_ERR_NO_FILE:
|
case \UPLOAD_ERR_NO_FILE:
|
||||||
|
|
@ -354,7 +360,7 @@ class UploadFile
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function getMaxSize() : int
|
public function getMaxSize(): int
|
||||||
{
|
{
|
||||||
return $this->maxSize;
|
return $this->maxSize;
|
||||||
}
|
}
|
||||||
|
|
@ -366,7 +372,7 @@ class UploadFile
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function setInterlaced(bool $isInterlaced) : void
|
public function setInterlaced(bool $isInterlaced): void
|
||||||
{
|
{
|
||||||
$this->isInterlaced = $isInterlaced;
|
$this->isInterlaced = $isInterlaced;
|
||||||
}
|
}
|
||||||
|
|
@ -378,7 +384,7 @@ class UploadFile
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function setMaxSize(int $maxSize) : void
|
public function setMaxSize(int $maxSize): void
|
||||||
{
|
{
|
||||||
$this->maxSize = $maxSize;
|
$this->maxSize = $maxSize;
|
||||||
}
|
}
|
||||||
|
|
@ -388,7 +394,7 @@ class UploadFile
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function getAllowedTypes() : array
|
public function getAllowedTypes(): array
|
||||||
{
|
{
|
||||||
return $this->allowedTypes;
|
return $this->allowedTypes;
|
||||||
}
|
}
|
||||||
|
|
@ -400,7 +406,7 @@ class UploadFile
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function setAllowedTypes(array $allowedTypes) : void
|
public function setAllowedTypes(array $allowedTypes): void
|
||||||
{
|
{
|
||||||
$this->allowedTypes = $allowedTypes;
|
$this->allowedTypes = $allowedTypes;
|
||||||
}
|
}
|
||||||
|
|
@ -412,7 +418,7 @@ class UploadFile
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function addAllowedTypes(string $allowedTypes) : void
|
public function addAllowedTypes(string $allowedTypes): void
|
||||||
{
|
{
|
||||||
$this->allowedTypes[] = $allowedTypes;
|
$this->allowedTypes[] = $allowedTypes;
|
||||||
}
|
}
|
||||||
|
|
@ -422,7 +428,7 @@ class UploadFile
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function getOutputDir() : string
|
public function getOutputDir(): string
|
||||||
{
|
{
|
||||||
return $this->outputDir;
|
return $this->outputDir;
|
||||||
}
|
}
|
||||||
|
|
@ -436,7 +442,7 @@ class UploadFile
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function setOutputDir(string $outputDir) : void
|
public function setOutputDir(string $outputDir): void
|
||||||
{
|
{
|
||||||
$this->outputDir = $outputDir;
|
$this->outputDir = $outputDir;
|
||||||
}
|
}
|
||||||
|
|
@ -446,7 +452,7 @@ class UploadFile
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function getFileName() : string
|
public function getFileName(): string
|
||||||
{
|
{
|
||||||
return $this->fileName;
|
return $this->fileName;
|
||||||
}
|
}
|
||||||
|
|
@ -460,7 +466,7 @@ class UploadFile
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function setFileName(string $fileName) : void
|
public function setFileName(string $fileName): void
|
||||||
{
|
{
|
||||||
$this->fileName = $fileName;
|
$this->fileName = $fileName;
|
||||||
}
|
}
|
||||||
|
|
@ -474,7 +480,7 @@ class UploadFile
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function setPreserveFileName(bool $preserveFileName) : void
|
public function setPreserveFileName(bool $preserveFileName): void
|
||||||
{
|
{
|
||||||
$this->preserveFileName = $preserveFileName;
|
$this->preserveFileName = $preserveFileName;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user