temp = explode(".", $file["file"]["name"]); $this->extension = end($this->temp); $this->file = $file; } function insert($id,$name='avatar'){ if ($this->cekFoto($this->file)){ //mkdir($this->user_file . $_SESSION['username'], 0700); //echo 'aksi : insert/update tapi file belum ada'; move_uploaded_file($this->file["file"]["tmp_name"], $this->user_file . $id . "/" . $name . "." .$this->extension); $this->hasil = array( 'lokasi' => $this->user_file . $id . "/" . $name . "." .$this->extension, 'bool' => true ); return true; } else{ echo "Return Code: " . $this->file["file"]["error"] . "
"; return false; } } function update($id,$name='avatar'){ if ($this->cekFoto($this->file)){ //echo 'aksi : update dan file sudah ada'; unlink($this->user_file . $id . "/" . $name . "." .$this->extension); move_uploaded_file($this->file["file"]["tmp_name"], $this->user_file . $id . "/" . $name . "." .$this->extension); $this->hasil = array( 'lokasi' => user_file . $id . "/" . $name . "." .$this->extension, 'bool' => true ); return true; } else{ echo "Return Code: " . $this->file["file"]["error"] . "
"; return false; } } function cekFoto($file){ if ((($file["file"]["type"] == "image/gif") || ($file["file"]["type"] == "image/jpeg") || ($file["file"]["type"] == "image/jpg") || ($file["file"]["type"] == "image/pjpeg") || ($file["file"]["type"] == "image/x-png") || ($file["file"]["type"] == "image/png")) && ($file["file"]["size"] < 2000000) && in_array($this->extension, $this->allowedExts)){ return true; }else{ return false; } } function getHasil(){ return $this->hasil; } /* function foto($file,$aksi,$jenis){ $allowedExts = array("gif", "jpeg", "jpg", "png"); $temp = explode(".", $file["file"]["name"]); $extension = end($temp); if ((($file["file"]["type"] == "image/gif") || ($file["file"]["type"] == "image/jpeg") || ($file["file"]["type"] == "image/jpg") || ($file["file"]["type"] == "image/pjpeg") || ($file["file"]["type"] == "image/x-png") || ($file["file"]["type"] == "image/png")) && ($file["file"]["size"] < 2000000) && in_array($extension, $allowedExts)){ if ($file["file"]["error"] > 0){ echo "Return Code: " . $file["file"]["error"] . "
"; } else{ if ((file_exists(user_file . $_SESSION['username'] . "/" . $jenis . "." .$extension)) && $aksi == 'insert'){ echo 'aksi : insert dan file sudah ada
'; echo $id . " already exists. "; $hasil = array( 'bool' => false ); } else if ((file_exists(user_file . $_SESSION['username'] . "/" . $jenis . "." .$extension)) && $aksi == 'update'){ echo 'aksi : update dan file sudah ada'; unlink(user_file . $_SESSION['username'] . "/" . $jenis . "." .$extension); move_uploaded_file($file["file"]["tmp_name"], user_file . $_SESSION['username'] . "/" . $jenis . "." .$extension); $hasil = array( 'lokasi' => user_file . $_SESSION['username'] . "/" . $jenis . "." .$extension, 'bool' => true ); } else{ mkdir(user_file . $_SESSION['username'], 0700); echo 'aksi : insert/update tapi file belum ada'; move_uploaded_file($file["file"]["tmp_name"], user_file . $_SESSION['username'] . "/" . $jenis . "." .$extension); $hasil = array( 'lokasi' => user_file . $_SESSION['username'] . "/" . $jenis . "." .$extension, 'bool' => true ); } } } else{ $hasil = array( 'bool' => false ); } return $hasil; } */ } ?>