result); if (!empty($hal)) { $page = $hal - 1; $MulaiAwal = $Batas * $page; } else if (!empty($hal) and $hal == 1) { $MulaiAwal = 0; } else if (empty($hal)) { $MulaiAwal = 0; } for ($i = $MulaiAwal; $i < $MulaiAwal+$Batas; $i++) { if (array_key_exists($i, $data)){ $new[$i] = $data[$i]; } } $pagination = ""; $jumlahData = sizeof($data); //echo "
".$jumlahData." Hasil"; if ($jumlahData > $Batas) { $pagination = $pagination.''; } $hasil = array( "paging" => $pagination, "data" => $new, "mulai" => $MulaiAwal, ); return $hasil; } public function getPaging($array){ return $this->pagination; } public function foto($file,$id = null,$aksi,$newid){ $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("upload/" . $id.".".$extension)) && $aksi == 'insert') { echo 'aksi : insert dan file sudah ada
'; echo $id . " already exists. "; $hasil = array( 'bool' => false ); } else if ((file_exists("upload/" . $id.".".$extension)) && $aksi == 'update') { echo 'aksi : update dan file sudah ada'; unlink("upload/" . $id.".".$extension); move_uploaded_file($file["file"]["tmp_name"], "upload/" . $newid.".".$extension); $hasil = array( 'lokasi' => "upload/" . $newid.".".$extension, 'bool' => true ); } else { echo 'aksi : insert/update tapi file belum ada'; move_uploaded_file($file["file"]["tmp_name"], "upload/" . $newid.".".$extension); $hasil = array( 'lokasi' => "upload/" . $newid.".".$extension, 'bool' => true ); } } } else { $hasil = array( 'bool' => false ); } return $hasil; } public function deletemhs($id){ if($this->delete('mahasiswa','nim = '.$id.'')){ $files = glob("upload/$id.*"); foreach ($files as $file) { unlink($file); } header('Location: index.php'); } else echo 'Gagal hapus '.$id.'.*'; } public function renamefoto($id,$newid){ $this->select('mahasiswa', 'foto', "nim='$id'"); $res = $this->getResult(); $file = $res['foto']; $path_parts = pathinfo($file); //echo $path_parts['dirname'], "\n"; //echo $path_parts['basename'], "\n"; //echo $path_parts['extension'], "\n"; //echo $path_parts['filename'], "\n"; rename ('upload/'.$id.'.'.$path_parts['extension'], 'upload/'.$newid.'.'.$path_parts['extension']); $newfile = 'upload/'.$newid.'.'.$path_parts['extension']; return $newfile; } } ?>