diff --git a/README.md b/README.md index 2bb0818..6e682c2 100755 --- a/README.md +++ b/README.md @@ -5,19 +5,18 @@ [![PHP from Packagist](https://img.shields.io/packagist/php-v/coffeecode/uploader.svg?style=flat-square)](https://packagist.org/packages/coffeecode/uploader) [![Latest Version](https://img.shields.io/github/release/robsonvleite/uploader.svg?style=flat-square)](https://github.com/robsonvleite/uploader/releases) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) -[![Build](https://img.shields.io/scrutinizer/build/g/robsonvleite/uploader.svg?style=flat-square)](https://scrutinizer-ci.com/g/robsonvleite/uploader) [![Quality Score](https://img.shields.io/scrutinizer/g/robsonvleite/uploader.svg?style=flat-square)](https://scrutinizer-ci.com/g/robsonvleite/uploader) [![Total Downloads](https://img.shields.io/packagist/dt/coffeecode/uploader.svg?style=flat-square)](https://packagist.org/packages/coffeecode/uploader) ###### Uploader is a set of small classes for sending images, files, and media received by a form of your application. The Uploader handles, validates and sends the files to your server. Image class can still handle sizes with the gd library. -Uploader é um conjunto de pequenas classes para envio de imagens, arquivos e midias recebidos por um formulário da sua +Uploader é um conjunto de pequenas classes para envio de imagens, arquivos e midias recebidos por um formulário de sua aplicação. O Uploader trata, valida e envia os arquivos a seu servidor. A classe de imagem ainda consegue tratar tamanhos com a biblioteca gd. ## About CoffeeCode -###### CoffeeCode is a set of small and optimized PHP components for common tasks. Held by Robson V. Leite, and the UpInside team. With them, you perform routine tasks with fewer lines, writing less and doing much more. +###### CoffeeCode is a set of small and optimized PHP components for common tasks. Held by Robson V. Leite and the UpInside team. With them you perform routine tasks with fewer lines, writing less and doing much more. CoffeeCode é um conjunto de pequenos e otimizados componentes PHP para tarefas comuns. Mantido por Robson V. Leite e a equipe UpInside. Com eles você executa tarefas rotineiras com poucas linhas, escrevendo menos e fazendo muito mais. @@ -52,7 +51,7 @@ composer require coffeecode/uploader Para mais detalhes sobre como usar o upload, veja uma pasta de exemplo no diretório do componente. Nela terá um exemplo de uso para cada classe. CoffeeCode Uploader funciona assim: -#### Upload an Image +#### Upload Image ```php upload($_FILES['image'], $_POST['name']); - echo ""; + echo ""; } catch (Exception $e) { - echo "

(!) $e->getMessage()

"; + echo "

(!) {$e->getMessage()}

"; } } ``` -#### Upload an File +#### Upload File ```php upload($_FILES['file'], $_POST['name']); - echo "

@CoffeeCode

"; + echo "

@CoffeeCode

"; } catch (Exception $e) { - echo "

(!) $e->getMessage()

"; + echo "

(!) {$e->getMessage()}

"; } } ``` -#### Upload an Media +#### Upload Media ```php upload($_FILES['file'], $_POST['name']); - echo "

@CoffeeCode

"; + echo "

@CoffeeCode

"; } catch (Exception $e) { - echo "

(!) $e->getMessage()

"; + echo "

(!) {$e->getMessage()}

"; } } ``` @@ -108,14 +107,16 @@ if ($_FILES) { ```php upload($_FILES['file'], $_POST['name']); - echo "

@CoffeeCode

"; + echo "

@CoffeeCode

"; } catch (Exception $e) { - echo "

(!) $e->getMessage()

"; + echo "

(!) {$e->getMessage()}

"; } } ``` @@ -132,7 +133,7 @@ try { } echo "Success!"; } catch (Exception $e) { - echo "

(!) $e->getMessage()

"; + echo "

(!) {$e->getMessage()}

"; } ``` diff --git a/example/file.php b/example/file.php index 0b4ae0a..fda1852 100755 --- a/example/file.php +++ b/example/file.php @@ -13,15 +13,13 @@ if ($_FILES) { try { $upload = $file->upload($_FILES['file'], $_POST['name']); - echo "

@CoffeeCode

"; + echo "

@CoffeeCode

"; } catch (Exception $e) { - echo "

(!) $e->getMessage()

"; + echo "

(!) {$e->getMessage()}

"; } } ?> - + diff --git a/example/image.php b/example/image.php index 579e666..b0b6bb3 100755 --- a/example/image.php +++ b/example/image.php @@ -12,15 +12,13 @@ if ($_FILES) { try { $upload = $image->upload($_FILES['image'], $_POST['name']); - echo ""; + echo ""; } catch (Exception $e) { - echo "

(!) $e->getMessage()

"; + echo "

(!) {$e->getMessage()}

"; } } ?> - + diff --git a/example/media.php b/example/media.php index c2f17d7..d3ab3bd 100755 --- a/example/media.php +++ b/example/media.php @@ -12,15 +12,13 @@ if ($_FILES) { try { $upload = $media->upload($_FILES['file'], $_POST['name']); - echo "

@CoffeeCode

"; + echo "

@CoffeeCode

"; } catch (Exception $e) { - echo "

(!) $e->getMessage()

"; + echo "

(!) {$e->getMessage()}

"; } } ?> - + diff --git a/example/send.php b/example/send.php index b27179f..aa20290 100755 --- a/example/send.php +++ b/example/send.php @@ -11,24 +11,20 @@ // "application/postscript" //], ["ai"], false); //SEM PASTAS DE ANO E MÊS - $postscript = new CoffeeCode\Uploader\Send( - "uploads", "postscript", [ + $postscript = new CoffeeCode\Uploader\Send("uploads", "postscript", [ "application/postscript" - ], ["ai"] - ); + ], ["ai"]); if ($_FILES) { try { $upload = $postscript->upload($_FILES['file'], $_POST['name']); - echo "

@CoffeeCode

"; + echo "

@CoffeeCode

"; } catch (Exception $e) { - echo "

(!) $e->getMessage()

"; + echo "

(!) {$e->getMessage()}

"; } } ?> - + diff --git a/src/File.php b/src/File.php index 27cdf6e..5f0dd38 100755 --- a/src/File.php +++ b/src/File.php @@ -64,7 +64,7 @@ public function upload(array $file, string $name): string } $this->name($name); - move_uploaded_file($file['tmp_name'], "$this->path/$this->name"); - return "$this->path/$this->name"; + move_uploaded_file($file['tmp_name'], "{$this->path}/{$this->name}"); + return "{$this->path}/{$this->name}"; } } diff --git a/src/Image.php b/src/Image.php index 089f25a..90faf30 100755 --- a/src/Image.php +++ b/src/Image.php @@ -43,12 +43,12 @@ public function upload(array $image, string $name, int $width = 2000, ?array $qu $this->name($name); if ($this->ext == "gif") { - move_uploaded_file($image['tmp_name'], "$this->path/$this->name"); - return "$this->path/$this->name"; + move_uploaded_file("{$image['tmp_name']}", "{$this->path}/{$this->name}"); + return "{$this->path}/{$this->name}"; } $this->imageGenerate($width, ($quality ?? ["jpg" => 75, "png" => 5])); - return "$this->path/$this->name"; + return "{$this->path}/{$this->name}"; } /** @@ -94,14 +94,14 @@ private function imageGenerate(int $width, array $quality): void if ($this->ext == "jpg") { imagecopyresampled($imageCreate, $this->file, 0, 0, 0, 0, $imageW, $imageH, $fileX, $fileY); - imagejpeg($imageCreate, "$this->path/$this->name", $quality['jpg']); + imagejpeg($imageCreate, "{$this->path}/{$this->name}", $quality['jpg']); } if ($this->ext == "png") { imagealphablending($imageCreate, false); imagesavealpha($imageCreate, true); imagecopyresampled($imageCreate, $this->file, 0, 0, 0, 0, $imageW, $imageH, $fileX, $fileY); - imagepng($imageCreate, "$this->path/$this->name", $quality['png']); + imagepng($imageCreate, "{$this->path}/{$this->name}", $quality['png']); } imagedestroy($this->file); diff --git a/src/Media.php b/src/Media.php index a9b107d..ec8b6b2 100755 --- a/src/Media.php +++ b/src/Media.php @@ -47,7 +47,7 @@ public function upload(array $media, string $name): string } $this->name($name); - move_uploaded_file($media['tmp_name'], "$this->path/$this->name"); - return "$this->path/$this->name"; + move_uploaded_file($media['tmp_name'], "{$this->path}/{$this->name}"); + return "{$this->path}/{$this->name}"; } } diff --git a/src/Send.php b/src/Send.php index 3940881..1e9e9a2 100755 --- a/src/Send.php +++ b/src/Send.php @@ -49,7 +49,7 @@ public function upload(array $file, string $name): string } $this->name($name); - move_uploaded_file($file['tmp_name'], "$this->path/$this->name"); - return "$this->path/$this->name"; + move_uploaded_file($file['tmp_name'], "{$this->path}/{$this->name}"); + return "{$this->path}/{$this->name}"; } } \ No newline at end of file diff --git a/src/Uploader.php b/src/Uploader.php index 632f321..94eeb3a 100755 --- a/src/Uploader.php +++ b/src/Uploader.php @@ -37,11 +37,11 @@ abstract class Uploader public function __construct(string $uploadDir, string $fileTypeDir, bool $monthYearPath = true) { $this->dir($uploadDir); - $this->dir("$uploadDir/$fileTypeDir"); - $this->path = "$uploadDir/$fileTypeDir"; + $this->dir("{$uploadDir}/{$fileTypeDir}"); + $this->path = "{$uploadDir}/{$fileTypeDir}"; if ($monthYearPath) { - $this->path("$uploadDir/$fileTypeDir"); + $this->path("{$uploadDir}/{$fileTypeDir}"); } } @@ -76,10 +76,10 @@ protected function name(string $name): string str_replace(" ", "-", trim(strtr(utf8_decode($name), utf8_decode($formats), $replace))) ); - $this->name = "$name." . $this->ext; + $this->name = "{$name}." . $this->ext; - if (file_exists("$this->path/$this->name") && is_file("$this->path/$this->name")) { - $this->name = "$name-" . time() . ".$this->ext"; + if (file_exists("{$this->path}/{$this->name}") && is_file("{$this->path}/{$this->name}")) { + $this->name = "{$name}-" . time() . ".{$this->ext}"; } return $this->name; } @@ -102,9 +102,9 @@ protected function path(string $path): void { list($yearPath, $mothPath) = explode("/", date("Y/m")); - $this->dir("$path/$yearPath"); - $this->dir("$path/$yearPath/$mothPath"); - $this->path = "$path/$yearPath/$mothPath"; + $this->dir("{$path}/{$yearPath}"); + $this->dir("{$path}/{$yearPath}/{$mothPath}"); + $this->path = "{$path}/{$yearPath}/{$mothPath}"; } /**