Фиксим мелкие ошибки.
This commit is contained in:
@@ -9,15 +9,15 @@
|
||||
|
||||
class Uploader
|
||||
{
|
||||
private $width = ['min' => 0, 'max' => 0];
|
||||
private $height = ['min' => 0, 'max' => 0];
|
||||
private $maxFileSizeMb;
|
||||
private $savePath;
|
||||
private $extensions = 'jpg|png|jpeg|gif';
|
||||
private $extMatches = [];
|
||||
private $FILE;
|
||||
private array $width = ['min' => 0, 'max' => 0];
|
||||
private array $height = ['min' => 0, 'max' => 0];
|
||||
private int $maxFileSizeMb;
|
||||
private string $savePath;
|
||||
private string $extensions = 'jpg|png|jpeg|gif';
|
||||
private array $extMatches = [];
|
||||
private array $FILE;
|
||||
private $cnm;
|
||||
public static $error;
|
||||
public static string $error;
|
||||
|
||||
public function __construct($name, $cnm = null)
|
||||
{
|
||||
@@ -29,22 +29,22 @@ class Uploader
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $max
|
||||
* @param int $min
|
||||
* @param int $max
|
||||
* @param int|null $min
|
||||
* @return void
|
||||
*/
|
||||
public function setWidth($max, $min = null)
|
||||
public function setWidth(int $max, ?int $min = null)
|
||||
{
|
||||
$this->width['min'] = is_null($min) ? $max : $min;
|
||||
$this->width['max'] = $max;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $max
|
||||
* @param int $min
|
||||
* @param int $max
|
||||
* @param int|null $min
|
||||
* @return void
|
||||
*/
|
||||
public function setHeight($max, $min = null)
|
||||
public function setHeight(int $max, ?int $min = null)
|
||||
{
|
||||
$this->height['min'] = is_null($min) ? $max : $min;
|
||||
$this->height['max'] = $max;
|
||||
@@ -63,7 +63,7 @@ class Uploader
|
||||
* @param string $path путь от корня до конечной папки без открывающего слеша.
|
||||
* @return void
|
||||
*/
|
||||
public function setSavePath($path)
|
||||
public function setSavePath(string $path)
|
||||
{
|
||||
$this->savePath = $_SERVER['DOCUMENT_ROOT'] . '/' . $path;
|
||||
}
|
||||
@@ -90,15 +90,15 @@ class Uploader
|
||||
* @param int $height
|
||||
* @return void
|
||||
*/
|
||||
public function setDimensions($width, $height)
|
||||
public function setDimensions(int $width, int $height)
|
||||
{
|
||||
$this->setWidth($width);
|
||||
$this->setHeight($height);
|
||||
}
|
||||
|
||||
private function hasNormalDimensions()
|
||||
private function hasNormalDimensions(): bool
|
||||
{
|
||||
list($width, $height) = getimagesize($this->FILE['tmp_name']);
|
||||
[$width, $height] = getimagesize($this->FILE['tmp_name']);
|
||||
if (!$width || !$height) {
|
||||
self::$error = 'Не подтянулись размеры файла.';
|
||||
return false;
|
||||
@@ -118,7 +118,7 @@ class Uploader
|
||||
return true;
|
||||
}
|
||||
|
||||
private function hasNormalFileSize()
|
||||
private function hasNormalFileSize(): bool
|
||||
{
|
||||
if (!$this->maxFileSizeMb) {
|
||||
$this->setMaxFileSize(2);
|
||||
@@ -130,7 +130,7 @@ class Uploader
|
||||
return true;
|
||||
}
|
||||
|
||||
private function hasNormalType()
|
||||
private function hasNormalType(): bool
|
||||
{
|
||||
if (
|
||||
!preg_match('/\.(' . $this->extensions . ')$/i', $this->FILE['name'], $this->extMatches) ||
|
||||
@@ -142,7 +142,7 @@ class Uploader
|
||||
return true;
|
||||
}
|
||||
|
||||
private function hasNormalFilePath()
|
||||
private function hasNormalFilePath(): bool
|
||||
{
|
||||
if (!$this->savePath || !is_dir($this->savePath)) {
|
||||
self::$error = 'Ошибка загрузки: нет такой папки.';
|
||||
@@ -167,7 +167,7 @@ class Uploader
|
||||
return [$fn2, $fn, $this->savePath . $fn];
|
||||
}
|
||||
|
||||
function saveimg()
|
||||
public function saveimg()
|
||||
{
|
||||
return $this->hasNormalFilePath() &&
|
||||
$this->hasNormalDimensions() &&
|
||||
|
||||
Reference in New Issue
Block a user