Advertisement
Armandobs14

Reading upload image properties

Aug 6th, 2017
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.62 KB | None | 0 0
  1.  public function getIssuePicture()
  2.     {
  3.         $id = time();
  4.  
  5.         $img = null;
  6.  
  7.         $_FILES = $_FILES["anexo"];
  8.  
  9.         $typeFile = $_FILES["type"];
  10.  
  11.         if (strstr($typeFile, "image")) {
  12.            
  13.             if (!empty($_FILES)) {
  14.  
  15.                 $tempFile = $_FILES['tmp_name'];
  16.  
  17.                 $type = explode(".", $_FILES['name']);
  18.  
  19.                 $isTypeAcepted = true;
  20.  
  21.                 $extImage = array("jpg", "png", "jpeg", "bmp");
  22.  
  23.                 if(!in_array(strtolower(end($type)),$extImage)){
  24.                     $isTypeAcepted = false;
  25.                 }
  26.  
  27.                 if (!$isTypeAcepted) {
  28.                     $this->messageJsonForJS(
  29.                         \project\dao\Result::INVALID_PARAMETER,
  30.                         "A imagem enviada não pertence a nenhum dos tipos aceitos!"
  31.                     );
  32.                 } else {
  33.                    
  34.                     $data = file_get_contents($tempFile);
  35.                     // $img = 'data:image/' . end($type) . ';base64,' . base64_encode($data);
  36.           $img = (object) array(
  37.             'string' => $data,
  38.             'mime' => 'image/' . end($type),
  39.             'type' => end($type)
  40.             );
  41.                 }
  42.  
  43.             } else {
  44.                 $this->messageJsonForJS(
  45.                     \project\dao\Result::INVALID_PARAMETER,
  46.                     "Selecione uma imagem."
  47.                 );
  48.             }
  49.         } else {
  50.             $this->messageJsonForJS(
  51.                 \project\dao\Result::INVALID_PARAMETER,
  52.                 "O arquivo submetido não é uma imagem."
  53.             );
  54.         }
  55.         return $img;
  56.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement