Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function submitfoto() {
- if(isset( $_FILES['FOTOPROFIL'] ) == TRUE){
- if($_FILES['FOTOPROFIL']['name'] != ""){
- $tipefile = $_FILES['FOTOPROFIL']['type'];
- $fileError = $_FILES['FOTOPROFIL']['error'];
- if($fileError == 0 and $tipefile =="image/jpeg") // and $tipefile =="image/jpeg" format Gambar Harus JPG
- {
- $fileName = $_FILES['FOTOPROFIL']['name'];
- move_uploaded_file($_FILES['FOTOPROFIL']['tmp_name'], $fileName);
- $lokasi=$fileName;
- $image=$lokasi;
- $orig_image = imagecreatefromjpeg($image);
- $image_info = getimagesize($image);
- $width_orig = $image_info[0]; // Mendapatkan ukuran panjang foto asli
- $height_orig = $image_info[1]; // Mendapatkan ukuran lebar foto asli
- $width = 150; // Ukuran Panjang
- $height = 150; // Ukuran Lebar
- $destination_image = imagecreatetruecolor($width, $height);
- imagecopyresampled($destination_image, $orig_image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
- imagejpeg($destination_image, $image, 100);
- $data = fopen ($image, 'rb');
- $size=filesize ($image);
- $contents= fread ($data, $size);
- fclose ($data);
- $encoded= base64_encode($contents);
- unlink($lokasi);
- $userid = $this->session->userdata('userid');
- $str = "SELECT COUNT(USERID) JML
- FROM MSTPENGGUNAFOTO
- WHERE CONVERT(NVARCHAR(50),USERID) = '$userid'";
- $query = $this->db->query($str);
- $jml = $query->result_array();
- if($jml[0]['JML']==0){
- $str2 = "INSERT INTO MSTPENGGUNAFOTO
- ( USERID
- , FOTOPROFIL )
- VALUES
- ( '".$userid."'
- ,'".$encoded."')";
- }else{
- $str2 = "UPDATE MSTPENGGUNAFOTO
- SET FOTOPROFIL = '".$encoded."'
- WHERE USERID = '".$userid."' ";
- }
- $this->db->simple_query($str2);
- }else{
- return false;
- }
- }
- }
- //return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement