-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from MohamedAmine-C/analysis-qBPgdA
Applied fixes from StyleCI
- Loading branch information
Showing
8 changed files
with
233 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
<?php | ||
|
||
namespace upload; | ||
|
||
class File extends Validate | ||
{ | ||
|
||
function __construct($key, $File = false) | ||
{ | ||
if (!$File) { | ||
$File = array( | ||
'name' => $_FILES[$key]['name'], | ||
'tmp_name' => $_FILES[$key]['tmp_name'] | ||
); | ||
public function __construct($key, $File = false) | ||
{ | ||
if (!$File) { | ||
$File = [ | ||
'name' => $_FILES[$key]['name'], | ||
'tmp_name' => $_FILES[$key]['tmp_name'], | ||
]; | ||
} | ||
$FilePath = $File['tmp_name']; | ||
$FileName = explode('.', $File['name']); | ||
$this->setName($FileName[0]); | ||
$this->setExtension(strtolower(end($FileName))); | ||
parent::__construct($FilePath); | ||
} | ||
$FilePath = $File['tmp_name']; | ||
$FileName = explode(".", $File["name"]); | ||
$this->setName($FileName[0]); | ||
$this->setExtension(strtolower(end($FileName))); | ||
parent::__construct($FilePath); | ||
} | ||
|
||
public function Upload($newPath) | ||
{ | ||
$newPath = $_SERVER["DOCUMENT_ROOT"].'/'.$newPath; | ||
if (is_dir($newPath) && is_writable($newPath)) { | ||
if (empty($this->Errors)) { | ||
$Path = $newPath.DIRECTORY_SEPARATOR.$this->getName().'.'.$this->getExtension(); | ||
move_uploaded_file($this->getTmpName(), $Path); | ||
return array('name' => $this->getName().'.'.$this->getExtension(), 'dir' => $Path); | ||
} else { | ||
return false; | ||
} | ||
} else { | ||
$this->Errors[] = "No access to this directory $newPath"; | ||
return false; | ||
} | ||
} | ||
public function Upload($newPath) | ||
{ | ||
$newPath = $_SERVER['DOCUMENT_ROOT'].'/'.$newPath; | ||
if (is_dir($newPath) && is_writable($newPath)) { | ||
if (empty($this->Errors)) { | ||
$Path = $newPath.DIRECTORY_SEPARATOR.$this->getName().'.'.$this->getExtension(); | ||
move_uploaded_file($this->getTmpName(), $Path); | ||
|
||
return ['name' => $this->getName().'.'.$this->getExtension(), 'dir' => $Path]; | ||
} else { | ||
return false; | ||
} | ||
} else { | ||
$this->Errors[] = "No access to this directory $newPath"; | ||
|
||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,70 @@ | ||
<?php | ||
|
||
namespace upload; | ||
|
||
class FileInfo implements FileInfoInterface | ||
{ | ||
|
||
private $Name; | ||
private $Extension; | ||
private $Size; | ||
private $TmpName; | ||
|
||
function __construct($FilePath) | ||
{ | ||
$this->Name = $this->Name ? $this->Name : pathinfo($FilePath, PATHINFO_FILENAME); | ||
$this->Size = filesize($FilePath); | ||
$this->TmpName = $FilePath; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return $this->Name; | ||
} | ||
|
||
public function setName($newName) | ||
{ | ||
$this->Name = $newName; | ||
} | ||
|
||
public function getSize($File = false) | ||
{ | ||
return $this->Size; | ||
} | ||
|
||
public function getExtension($File = false) | ||
{ | ||
return $this->Extension; | ||
} | ||
|
||
public function setExtension($newExtension) | ||
{ | ||
$this->Extension = $newExtension; | ||
} | ||
|
||
public function getTmpName() | ||
{ | ||
return $this->TmpName; | ||
} | ||
|
||
public function setTmpName($TmpName) | ||
{ | ||
$this->TmpName = $TmpName; | ||
} | ||
|
||
public function Compress($quality) | ||
{ | ||
$info = getimagesize($this->TmpName); | ||
|
||
if ($info['mime'] == 'image/jpeg') | ||
$image = imagecreatefromjpeg($this->TmpName); | ||
|
||
elseif ($info['mime'] == 'image/gif') | ||
$image = imagecreatefromgif($this->TmpName); | ||
|
||
elseif ($info['mime'] == 'image/png') | ||
$image = imagecreatefrompng($this->TmpName); | ||
|
||
imagejpeg($image, $this->TmpName, $quality); | ||
|
||
return $this->TmpName; | ||
} | ||
|
||
private $Name; | ||
private $Extension; | ||
private $Size; | ||
private $TmpName; | ||
|
||
public function __construct($FilePath) | ||
{ | ||
$this->Name = $this->Name ? $this->Name : pathinfo($FilePath, PATHINFO_FILENAME); | ||
$this->Size = filesize($FilePath); | ||
$this->TmpName = $FilePath; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return $this->Name; | ||
} | ||
|
||
public function setName($newName) | ||
{ | ||
$this->Name = $newName; | ||
} | ||
|
||
public function getSize($File = false) | ||
{ | ||
return $this->Size; | ||
} | ||
|
||
public function getExtension($File = false) | ||
{ | ||
return $this->Extension; | ||
} | ||
|
||
public function setExtension($newExtension) | ||
{ | ||
$this->Extension = $newExtension; | ||
} | ||
|
||
public function getTmpName() | ||
{ | ||
return $this->TmpName; | ||
} | ||
|
||
public function setTmpName($TmpName) | ||
{ | ||
$this->TmpName = $TmpName; | ||
} | ||
|
||
public function Compress($quality) | ||
{ | ||
$info = getimagesize($this->TmpName); | ||
|
||
if ($info['mime'] == 'image/jpeg') { | ||
$image = imagecreatefromjpeg($this->TmpName); | ||
} elseif ($info['mime'] == 'image/gif') { | ||
$image = imagecreatefromgif($this->TmpName); | ||
} elseif ($info['mime'] == 'image/png') { | ||
$image = imagecreatefrompng($this->TmpName); | ||
} | ||
|
||
imagejpeg($image, $this->TmpName, $quality); | ||
|
||
return $this->TmpName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
<?php | ||
|
||
namespace upload; | ||
|
||
interface FileInfoInterface | ||
{ | ||
public function getName(); | ||
public function setName($newName); | ||
public function getSize(); | ||
public function getExtension(); | ||
public function setExtension($newExtension); | ||
public function getTmpName(); | ||
public function setTmpName($tmpName); | ||
public function getName(); | ||
|
||
public function setName($newName); | ||
|
||
public function getSize(); | ||
|
||
public function getExtension(); | ||
|
||
public function setExtension($newExtension); | ||
|
||
public function getTmpName(); | ||
|
||
public function setTmpName($tmpName); | ||
} |
Oops, something went wrong.