Skip to content
Permalink
Browse files

Criado o sistema de upload usando a abstração Storage do Laravel

  • Loading branch information
rodrigodevigo authored and edersoares committed Jun 6, 2019
1 parent 58ceaf1 commit d1c615f43becaaca82a8053f37e322310c60064a
@@ -29,7 +29,9 @@
"predis/predis": "^1.1",
"prettus/l5-repository": "^2.6",
"swiftmailer/swiftmailer": "^6.1",
"tooleks/laravel-asset-version": "^1.0"
"tooleks/laravel-asset-version": "^1.0",
"league/flysystem-aws-s3-v3": "~1.0",
"league/flysystem-cached-adapter": "~1.0"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.2",
@@ -42,7 +44,9 @@
"myclabs/deep-copy": "^1.7",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^2.0",
"phpunit/phpunit": "^7.0"
"phpunit/phpunit": "^7.0",
"league/flysystem-aws-s3-v3": "~1.0",
"league/flysystem-cached-adapter": "~1.0"
},
"autoload": {
"classmap": [
@@ -13,7 +13,7 @@
|
*/

'default' => env('FILESYSTEM_DRIVER', 'local'),
'default' => env('FILESYSTEM_CLOUD', 'public'),

/*
|--------------------------------------------------------------------------
@@ -51,19 +51,28 @@
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'url' => '/storage',
'visibility' => 'public',
],

'minio' => [
'driver' => 's3',
'endpoint' => env('MINIO_ENDPOINT', 'http://127.0.0.1:9000'),
'use_path_style_endpoint' => true,
'key' => env('AWS_KEY'),
'secret' => env('AWS_SECRET'),
'region' => env('AWS_REGION'),
'bucket' => env('AWS_BUCKET'),
],

's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'region' => env('AWS_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
],

],

];
@@ -19,6 +19,7 @@ services:
links:
- postgres
- redis
- minio
environment:
CORE_EXT_CONFIGURATION_ENV: development
XDEBUG_IDEKEY: xdebug
@@ -48,3 +49,16 @@ services:
restart: always
ports:
- 6379

minio:
container_name: ieducar-minio
image: minio/minio
volumes:
- ./data1:/data
restart: always
ports:
- 9001:9000
environment:
MINIO_ACCESS_KEY: minio
MINIO_SECRET_KEY: minio123
command: server /data
@@ -1348,7 +1348,7 @@ private function validaDataNascimento()
protected function savePhoto($id)
{
if ($this->objPhoto!=null) {
$caminhoFoto = $this->objPhoto->sendPicture($id);
$caminhoFoto = $this->objPhoto->sendPicture();
if ($caminhoFoto!='') {
//new clsCadastroFisicaFoto($id)->exclui();
$obj = new clsCadastroFisicaFoto($id, $caminhoFoto);
@@ -54,21 +54,14 @@ function __construct($file, $maxSize = NULL,
}

function sendFile(){


$tmp = $this->file["tmp_name"];
include('s3_config.php');

//Rename file name.
$actual_file_name = $directory.time().md5($this->file["name"]);
if($s3->putObjectFile($tmp, $bucket , $actual_file_name, S3::ACL_PUBLIC_READ) )
{

$s3file='http://'.$bucket.'.s3.amazonaws.com/'.$actual_file_name;
return $s3file;
}
else{
$this->errorMessage = "Ocorreu um erro no servidor ao enviar arquivo. Tente novamente.";

$file = new File($tmp);
if (Storage::put('/', $file, 'public')) {
$filePath= Storage::url($file->hashName());
return $filePath;
} else {
$this->errorMessage = "Ocorreu um erro no servidor ao enviar foto. Tente novamente.";
return '';
}
}
@@ -53,19 +53,14 @@ function __construct($file, $maxSize = NULL,
}

function sendFile(){


$tmp = $this->file["tmp_name"];
include('s3_config.php');
//Rename file name.
$actual_file_name = $directory.time().md5($this->file["name"]);
if($s3->putObjectFile($tmp, $bucket , $actual_file_name, S3::ACL_PUBLIC_READ) )
{
$s3file='http://'.$bucket.'.s3.amazonaws.com/'.$actual_file_name;
return $s3file;
}
else{
$this->errorMessage = "Ocorreu um erro no servidor ao enviar arquivo. Tente novamente.";

$file = new File($tmp);
if (Storage::put('/', $file, 'public')) {
$filePath= Storage::url($file->hashName());
return $filePath;
} else {
$this->errorMessage = "Ocorreu um erro no servidor ao enviar foto. Tente novamente.";
return '';
}
}
@@ -29,6 +29,10 @@
* @version $Id$
*/

use Illuminate\Support\Facades\Storage;
use Illuminate\Http\File;


class PictureController {

var $imageFile;
@@ -73,21 +77,17 @@ function __construct($imageFile, $maxWidth = NULL, $maxHeight = NULL, $maxSize =
* @author Lucas Schmoeller da Silva - lucas@portabilis.com
* @return String
*/
function sendPicture($imageName){

$this->imageName = $imageName;
function sendPicture(){

$tmp = $this->imageFile["tmp_name"];
include('s3_config.php');
//Rename image name.

$file = new File($tmp);

$actual_image_name = $directory.$this->imageName;
if($s3->putObjectFile($tmp, $bucket , $actual_image_name, S3::ACL_PUBLIC_READ) )
{

$s3file='http://'.$bucket.'.s3.amazonaws.com/'.$actual_image_name;
return $s3file;
}
else{
$this->imageName = $file->hashName();
if (Storage::put('/', $file, 'public')) {
$filePath= Storage::url($file->hashName());
return $filePath;
} else {
$this->errorMessage = "Ocorreu um erro no servidor ao enviar foto. Tente novamente.";
return '';
}
@@ -6,6 +6,9 @@
require_once 'include/RDStationAPI.class.php';
require_once 'image_check.php';

use Illuminate\Support\Facades\Storage;
use Illuminate\Http\File;

class clsIndex extends clsBase
{
public function Formular()
@@ -113,7 +116,7 @@ public function Gerar()
}

if ($foto) {
$this->campoRotulo('fotoAtual_', 'Foto atual', '<img height="117" src="' . $foto . '"/>');
$this->campoRotulo('fotoAtual_', 'Foto atual', '<img height="117" src="' .$foto. '"/>');
$this->inputsHelper()->checkbox('file_delete', ['label' => 'Excluir a foto']);
$this->campoArquivo('file', 'Trocar foto', $this->arquivoFoto, 40, '<br/> <span style="font-style: italic; font-size= 10px;">* Recomenda-se imagens nos formatos jpeg, jpg, png e gif. Tamanho m&aacute;ximo: 150KB</span>');
} else {
@@ -342,7 +345,7 @@ public function validatePhoto()
public function savePhoto($id)
{
if ($this->objPhoto != null) {
$caminhoFoto = $this->objPhoto->sendPicture($id);
$caminhoFoto = $this->objPhoto->sendPicture();
if ($caminhoFoto != '') {
$obj = new clsCadastroFisicaFoto($id, $caminhoFoto);
$detalheFoto = $obj->detalhe();
@@ -1685,7 +1685,7 @@ protected function savePhoto($id)
{
if ($this->objPhoto != null) {
//salva foto com data, para evitar problemas com o cache do navegador
$caminhoFoto = $this->objPhoto->sendPicture($id) . '?' . date('Y-m-d-H:i:s');
$caminhoFoto = $this->objPhoto->sendPicture();

if ($caminhoFoto != '') {
//new clsCadastroFisicaFoto($id)->exclui();

0 comments on commit d1c615f

Please sign in to comment.
You can’t perform that action at this time.