-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Criado informação de criação e alteração de um registro. Adição de foto ao cadastro do cliente. Correção de bugs
- Loading branch information
1 parent
bfc3e80
commit c0d9eb5
Showing
12 changed files
with
266 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
require_once 'model/photoModel.php'; | ||
require_once 'controller/CustomerController.php'; | ||
|
||
class PhotoController { | ||
|
||
public function new( $cpf ){ | ||
require_once 'view/photo_new.php'; | ||
} | ||
|
||
public function save( $cpf ){ | ||
$photo = new Photo(); | ||
$photo->setCPF($cpf); | ||
|
||
if(isset($_FILES['photo'])){ | ||
$errors= array(); | ||
$file_name = $_FILES['photo']['name']; | ||
$file_ext = pathinfo($file_name, PATHINFO_EXTENSION); | ||
$file_name_2 = md5($cpf).".".$file_ext; | ||
$file_size =$_FILES['photo']['size']; | ||
$file_tmp =$_FILES['photo']['tmp_name']; | ||
$file_type=$_FILES['photo']['type']; | ||
@$file_ext=strtolower(end(explode('.',$_FILES['photo']['name']))); | ||
|
||
$extensions= array("jpeg","jpg","png"); | ||
|
||
if(in_array($file_ext,$extensions)=== false){ | ||
$errors[]="extension not allowed, please choose a JPEG or PNG file."; | ||
} | ||
|
||
if($file_size > 2097152){ | ||
$errors[]='File size must be excately 2 MB'; | ||
} | ||
|
||
if(empty($errors)==true){ | ||
move_uploaded_file($file_tmp,"images/".$file_name_2); | ||
|
||
$file_name_3 = md5($cpf).".jpg"; | ||
$image = new Imagick("images/".$file_name_3); | ||
$image->readImage("images/".$file_name_2); | ||
$image->resizeImage(133,133,Imagick::FILTER_LANCZOS,1); | ||
$image->setImageFormat('jpeg'); | ||
$image->setImageCompressionQuality(95); | ||
$image->stripImage(); | ||
|
||
$image->writeImage("images/".$file_name_3); | ||
if($file_type != "image/jpeg"){ | ||
unlink("images/".$file_name_2); | ||
} | ||
|
||
$photo->setPhoto($file_name_3); | ||
$photo->post_photo_save(); | ||
CustomerController::edit($photo->getCPF()); | ||
|
||
}else{ | ||
CustomerController::edit($cpf); | ||
} | ||
} | ||
} | ||
|
||
} | ||
?> |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
include_once 'connection.php'; | ||
|
||
class Photo extends Connection{ | ||
private $id; | ||
private $cpf; | ||
private $photo; | ||
|
||
public function setId($id){ | ||
$this->id=$id; | ||
return $this; | ||
} | ||
|
||
public function setCPF($cpf){ | ||
$this->cpf=$cpf; | ||
return $this; | ||
} | ||
|
||
public function setPhoto($photo){ | ||
$this->photo=$photo; | ||
return $this; | ||
} | ||
|
||
public function getId(){ | ||
return $this->id; | ||
} | ||
|
||
public function getCPF(){ | ||
return $this->cpf; | ||
} | ||
|
||
public function getPhoto(){ | ||
return $this->photo; | ||
} | ||
|
||
function photo_save(){ | ||
$sql_query = "UPDATE public.clientes SET photo='" . $this->getPhoto() . "' WHERE cpf='" . $this->getCPF() . "'"; | ||
$pdo = $this->o_db; | ||
$stmt = $pdo->prepare($sql_query); | ||
$stmt->execute(); | ||
$row = $stmt->fetch(); | ||
return $row; | ||
} | ||
|
||
function post_photo_save(){ | ||
$result = $this->photo_save(); | ||
return $result; | ||
} | ||
|
||
} | ||
?> |
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
Oops, something went wrong.