Advertisement
Guest User

Upload Foto MSSQL

a guest
Dec 8th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.73 KB | None | 0 0
  1. public function submitfoto() {
  2.         if(isset( $_FILES['FOTOPROFIL'] ) == TRUE){
  3.             if($_FILES['FOTOPROFIL']['name'] != ""){
  4.                 $tipefile = $_FILES['FOTOPROFIL']['type'];
  5.                 $fileError = $_FILES['FOTOPROFIL']['error'];
  6.                 if($fileError == 0 and $tipefile =="image/jpeg") //  and $tipefile =="image/jpeg" format Gambar Harus JPG
  7.                 {
  8.                     $fileName = $_FILES['FOTOPROFIL']['name'];
  9.                     move_uploaded_file($_FILES['FOTOPROFIL']['tmp_name'], $fileName);
  10.                     $lokasi=$fileName;
  11.                     $image=$lokasi;
  12.  
  13.                     $orig_image = imagecreatefromjpeg($image);
  14.                     $image_info = getimagesize($image);
  15.                     $width_orig  = $image_info[0]; // Mendapatkan ukuran panjang foto asli
  16.                     $height_orig = $image_info[1]; // Mendapatkan ukuran lebar foto asli
  17.                     $width = 150; // Ukuran Panjang
  18.                     $height = 150; // Ukuran Lebar
  19.                     $destination_image = imagecreatetruecolor($width, $height);
  20.                     imagecopyresampled($destination_image, $orig_image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
  21.                     imagejpeg($destination_image, $image, 100);
  22.  
  23.                     $data = fopen ($image, 'rb');
  24.                     $size=filesize ($image);
  25.                     $contents= fread ($data, $size);
  26.                     fclose ($data);
  27.                     $encoded= base64_encode($contents);
  28.                     unlink($lokasi);
  29.                    
  30.                     $userid = $this->session->userdata('userid');
  31.                     $str = "SELECT COUNT(USERID) JML
  32.                                FROM MSTPENGGUNAFOTO
  33.                            WHERE CONVERT(NVARCHAR(50),USERID) = '$userid'";
  34.                     $query = $this->db->query($str);
  35.                     $jml = $query->result_array();
  36.                     if($jml[0]['JML']==0){
  37.                         $str2 = "INSERT INTO MSTPENGGUNAFOTO
  38.                                        ( USERID
  39.                                        , FOTOPROFIL )
  40.                                  VALUES
  41.                                        ( '".$userid."'
  42.                                        ,'".$encoded."')";
  43.                     }else{
  44.                         $str2 = "UPDATE MSTPENGGUNAFOTO
  45.                                    SET FOTOPROFIL = '".$encoded."'
  46.                                  WHERE USERID = '".$userid."' ";
  47.                     }
  48.                     $this->db->simple_query($str2);
  49.                 }else{
  50.                     return false;
  51.                 }
  52.             }
  53.         }
  54.         //return true;
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement