Дозаливка
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
/**
|
||||
* Åäèíàÿ ôóíêöèÿ äëÿ çàëèâêè ôàéëîâ íà ñåðâåð.
|
||||
*
|
||||
* @version 1
|
||||
* @author Ivor Barhansky <me@lopar.space>
|
||||
* @version 1
|
||||
*/
|
||||
|
||||
class Uploader
|
||||
@@ -16,15 +16,15 @@ class Uploader
|
||||
private $extensions = 'jpg|png|jpeg|gif';
|
||||
private $extMatches = [];
|
||||
private $FILE;
|
||||
private $cnm = null;
|
||||
private $cnm;
|
||||
public static $error;
|
||||
|
||||
public function __construct($name, $cnm = null)
|
||||
{
|
||||
$this->FILE = $_FILES;
|
||||
if (!$this->FILE[$name]) {
|
||||
if (!isset($_FILES[$name])) {
|
||||
return;
|
||||
}
|
||||
$this->FILE = $_FILES[$name];
|
||||
$this->cnm = $cnm;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ class Uploader
|
||||
*/
|
||||
public function setMaxFileSize($megabytes)
|
||||
{
|
||||
$this->maxFileSizeMb = $megabytes * (1024 * 1024);
|
||||
$this->maxFileSizeMb = $megabytes;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,7 +65,7 @@ class Uploader
|
||||
*/
|
||||
public function setSavePath($path)
|
||||
{
|
||||
$this->savePath = __DIR__ . '/' . $path;
|
||||
$this->savePath = $_SERVER['DOCUMENT_ROOT'] . '/' . $path;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,17 +99,20 @@ class Uploader
|
||||
private function hasNormalDimensions()
|
||||
{
|
||||
list($width, $height) = getimagesize($this->FILE['tmp_name']);
|
||||
if (!$width || !$height) {
|
||||
self::$error = 'Íå ïîäòÿíóëèñü ðàçìåðû ôàéëà.';
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
$width < $this->width['min'] ||
|
||||
$width > $this->width['max'] ||
|
||||
$height < $this->height['min'] ||
|
||||
$height > $this->height['max']
|
||||
($width < $this->width['min'] || $width > $this->width['max']) ||
|
||||
($height < $this->height['min'] || $height > $this->height['max'])
|
||||
) {
|
||||
self::$error = "Òðåáîâàíèÿ ê ðàçìåðó [{$this->width['max']}x{$this->height['max']}] íå ñîáëþäåíû.";
|
||||
self::$error = 'Òðåáîâàíèÿ ê ðàçìåðó: ';
|
||||
if ($this->width['min'] !== $this->width['max'] || $this->height['min'] !== $this->height['max']) {
|
||||
self::$error .= " Ìèíèìóì [{$this->width['min']}x{$this->height['min']}].";
|
||||
self::$error .= "îò [{$this->width['min']} x {$this->height['min']}] äî ";
|
||||
}
|
||||
self::$error .= " <span style='color:red;'>[{$width}x$height]</span>";
|
||||
self::$error .= "[{$this->width['max']} x {$this->height['max']}].";
|
||||
self::$error .= " Òåêóùèé ðàçìåð [$width x $height]";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -120,7 +123,7 @@ class Uploader
|
||||
if (!$this->maxFileSizeMb) {
|
||||
$this->setMaxFileSize(2);
|
||||
}
|
||||
if ($this->FILE['size'] > $this->maxFileSizeMb || $this->FILE['size'] <=0) {
|
||||
if ($this->FILE['size'] > $this->maxFileSizeMb * (1024 * 1024) || $this->FILE['size'] <= 0) {
|
||||
self::$error = 'Íåâåðíûé ðàçìåð ôàéëà. Ìàêñèìàëüíûé ðàçìåð ôàéëà ' . $this->maxFileSizeMb . ' ÌÁ';
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user