log invaid upload permission/file

This commit is contained in:
Dennis Eichhorn 2020-09-06 21:13:04 +02:00
parent 4ff9b1f93e
commit d211936a37

View File

@ -1,4 +1,5 @@
<?php
/**
* Orange Management
*
@ -10,12 +11,13 @@
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Media\Models;
use phpOMS\System\File\FileUtils;
use phpOMS\System\File\Local\Directory;
use phpOMS\Log\FileLogger;
/**
* Upload.
@ -105,7 +107,7 @@ class UploadFile
bool $absolute = false,
string $encryptionKey = '',
string $encoding = 'UTF-8'
) : array {
): array {
$result = [];
if (\count($files) === \count($files, \COUNT_RECURSIVE)) {
@ -169,7 +171,11 @@ class UploadFile
}
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)) {
@ -249,7 +255,7 @@ class UploadFile
*
* @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 = '';
$limit = 0;
@ -284,7 +290,7 @@ class UploadFile
*
* @since 1.0.0
*/
private function interlace(string $extension, string $path) : void
private function interlace(string $extension, string $path): void
{
if ($extension === 'png') {
$img = \imagecreatefrompng($path);
@ -318,7 +324,7 @@ class UploadFile
*
* @since 1.0.0
*/
private function findOutputDir() : string
private function findOutputDir(): string
{
do {
$rndPath = \str_pad(\dechex(\mt_rand(0, 65535)), 4, '0', \STR_PAD_LEFT);
@ -336,7 +342,7 @@ class UploadFile
*
* @since 1.0.0
*/
private function getUploadError($error) : int
private function getUploadError($error): int
{
switch ($error) {
case \UPLOAD_ERR_NO_FILE:
@ -354,7 +360,7 @@ class UploadFile
*
* @since 1.0.0
*/
public function getMaxSize() : int
public function getMaxSize(): int
{
return $this->maxSize;
}
@ -366,7 +372,7 @@ class UploadFile
*
* @since 1.0.0
*/
public function setInterlaced(bool $isInterlaced) : void
public function setInterlaced(bool $isInterlaced): void
{
$this->isInterlaced = $isInterlaced;
}
@ -378,7 +384,7 @@ class UploadFile
*
* @since 1.0.0
*/
public function setMaxSize(int $maxSize) : void
public function setMaxSize(int $maxSize): void
{
$this->maxSize = $maxSize;
}
@ -388,7 +394,7 @@ class UploadFile
*
* @since 1.0.0
*/
public function getAllowedTypes() : array
public function getAllowedTypes(): array
{
return $this->allowedTypes;
}
@ -400,7 +406,7 @@ class UploadFile
*
* @since 1.0.0
*/
public function setAllowedTypes(array $allowedTypes) : void
public function setAllowedTypes(array $allowedTypes): void
{
$this->allowedTypes = $allowedTypes;
}
@ -412,7 +418,7 @@ class UploadFile
*
* @since 1.0.0
*/
public function addAllowedTypes(string $allowedTypes) : void
public function addAllowedTypes(string $allowedTypes): void
{
$this->allowedTypes[] = $allowedTypes;
}
@ -422,7 +428,7 @@ class UploadFile
*
* @since 1.0.0
*/
public function getOutputDir() : string
public function getOutputDir(): string
{
return $this->outputDir;
}
@ -436,7 +442,7 @@ class UploadFile
*
* @since 1.0.0
*/
public function setOutputDir(string $outputDir) : void
public function setOutputDir(string $outputDir): void
{
$this->outputDir = $outputDir;
}
@ -446,7 +452,7 @@ class UploadFile
*
* @since 1.0.0
*/
public function getFileName() : string
public function getFileName(): string
{
return $this->fileName;
}
@ -460,7 +466,7 @@ class UploadFile
*
* @since 1.0.0
*/
public function setFileName(string $fileName) : void
public function setFileName(string $fileName): void
{
$this->fileName = $fileName;
}
@ -474,7 +480,7 @@ class UploadFile
*
* @since 1.0.0
*/
public function setPreserveFileName(bool $preserveFileName) : void
public function setPreserveFileName(bool $preserveFileName): void
{
$this->preserveFileName = $preserveFileName;
}