large files showing in KB after uploading to google drive

We are trying to use this plugin code in our php script

https://github.com/wp-plugins/google-drive-wp-media/tree/master/gdwpm-api

We modified code and using successfully in our project, But its working only for small files, When we upload large files to google drive files showing only in KB size. May be only last chunk is uploaded to google drive for large files, We tried to solve this error but failed, Please check and tell what we are doing wrong.

Here is our modified files.

index.php

		<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">

	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
	<script src="http://cdn.jsdelivr.net/bootstrap/3.3.2/js/bootstrap.min.js"></script>
	<script type='text/javascript' src='http://myweb.com/wp-admin/load-scripts.php?c=0&amp;load%5B%5D=jquery-core,jquery-migrate,utils,plupload&amp;ver=4.4.2'></script>


	<div class="container">
	<div id="tabs-2" aria-labelledby="ui-id-12" class="ui-tabs-panel ui-widget-content ui-corner-bottom" role="tabpanel" aria-hidden="false" style="display: block;">
					<p style="display: flex; align-items: center;">
						Select folder: &nbsp;<select id="folder_pilian_aplod" name="folder_pilian_aplod" style="display: block;"><option value="0B0pm8dZPprJ-cElGclFoc2tVZ1E">testdata</option></select>
					</p>
						<!--<p>Short Description: <input type="text" name="gdwpm_aplod_deskrip" value="" size="65" placeholder="Optional"></p>-->
					<p>
						</p><ul>
					
							<li><dfn>Accepted Media MIME types: */*</dfn>
							<!--	<br />&nbsp;<dfn>All Filetypes are allowed.</dfn>
							--></li>
						</ul> 
					<p></p>
						<ul id="filelist"></ul>
					<br>
					<button id="gdwpm_tombol_bersih" style="display:none;float:right;" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary" role="button"><span class="ui-button-icon-primary ui-icon ui-icon-grip-dotted-horizontal"></span><span class="ui-button-text">Clear List</span></button>




Choose your files:

Add to Media Library. (just linked to, all files still remain in Google Drive)


    	

uploader.php

 <?php
error_reporting(E_ALL); ini_set('display_errors', 1); 
require_once 'gdwpm-api/Google_Client.php';
require_once 'gdwpm-api/contrib/Google_DriveService.php';
require_once 'gwbp.php';

set_time_limit(600000000);

global $cek_kunci, $gdwpm_opt_akun, $gdwpm_service, $gdwpm_apiConfig;
if (empty($_FILES) || $_FILES["file"]["error"]) {
				die('<div class="error"><p>Oops.. error, upload failed! '.$_FILES["file"]["error"].'</p></div>');
			}
			if (isset($_REQUEST["gdpwm_nama_file"])) {
				$filename = $_REQUEST["gdpwm_nama_file"];
			} elseif (!empty($_FILES)) {
				$filename = $_FILES["file"]["name"];
			} else {
				$filename = uniqid("file_");
			}
$targetDir = ini_get("upload_tmp_dir");
			$maxFileAge = 5000 * 3600; // Temp file age in seconds
			// Create target dir
			if (!file_exists($targetDir)) {
				//@mkdir($targetDir);
				if (!file_exists($targetDir = sys_get_temp_dir())){
					$upload_dir = wp_upload_dir();
					if (!file_exists($targetDir = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'gdwpm-tmp')) {
						@mkdir($targetDir);
					}
				}
			}
$filePath = $targetDir . DIRECTORY_SEPARATOR . $filename;

			// Chunking might be enabled
			$chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
			$chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0;

			if (!is_dir($targetDir) || !$dir = opendir($targetDir)) {
				die('<div class="error"><p>Oops.. error. Failed to open temp directory.</p></div>');
			}


while (($file = readdir($dir)) !== false) {
				$tmpfilePath = $targetDir . DIRECTORY_SEPARATOR . $file;

				// If temp file is current file proceed to the next
				if ($tmpfilePath == "{$filePath}.part") {
					continue;
				}

				// Remove temp file if it is older than the max age and is not the current file
				if (preg_match('/\.part$/', $file) && (filemtime($tmpfilePath) < time() - $maxFileAge)) {
					@unlink($tmpfilePath);
				}
			}
			closedir($dir);

			// Open temp file
			if (!$out = @fopen("{$filePath}.part", $chunks ? "ab" : "wb")) {
				die('<div class="error"><p>Oops.. error. Failed to open output stream.</p></div>');
			}
if (!empty($_FILES)) {
				if ($_FILES["file"]["error"] || !is_uploaded_file($_FILES["file"]["tmp_name"])) {
					die('<div class="error"><p>Oops.. error. Failed to move uploaded file.</p></div>');
				}

				// Read binary input stream and append it to temp file
				if (!$in = @fopen($_FILES["file"]["tmp_name"], "rb")) {
					die('<div class="error"><p>Oops.. error. Failed to open input stream.</p></div>');
				}
			} else {        
				if (!$in = @fopen("php://input", "rb")) {
					die('<div class="error"><p>Oops.. error. Failed to open input stream.</p></div>');
				}
			}

			while ($buff = fread($in, 4096)) {
				fwrite($out, $buff);
			}

			@fclose($out);
			@fclose($in);

		



// Check if file has been uploaded
			if (!$chunks || $chunk == $chunks - 1) {
				// Strip the temp .part suffix off 
				if($filePath){
					rename("{$filePath}.part", $filePath);
				}else{					
					$filePath = $_FILES["file"]["tmp_name"];
				}
			
$gdwpm_opt_imel = '[email protected]';
$gdwpm_opt_klaen_aidi = 'myid';
$gdwpm_opt_nama_service = '[email protected]';
$gdwpm_opt_kunci_rhs = 'UploadFiles-f15596286d09.p12';
			
			$gdwpm_opt_akun = array($gdwpm_opt_imel, $gdwpm_opt_klaen_aidi, $gdwpm_opt_nama_service, $gdwpm_opt_kunci_rhs);
		

			
					$gdwpm_service = new GDWPMBantuan( $gdwpm_opt_akun[1], $gdwpm_opt_akun[2], $gdwpm_opt_akun[3] );
			

					//$mime_berkas_arr = wp_check_filetype($filename);

$finfo = new finfo;
 
$mime_berkas_arr['type'] = $finfo->file($filePath, FILEINFO_MIME);
//print_r($mime_berkas_arr);
					$mime_berkas = $mime_berkas_arr['type'];
					if(empty($mime_berkas)){$mime_berkas = $_FILES['file']['type'];}
					$folder_ortu = preg_replace("/[^a-zA-Z0-9]+/", " ", $_POST['gdpwm_nm_br']);
					$folder_ortu = trim(($folder_ortu));
					$folderId = $_POST['gdpwm_nm_id'];
					$nama_polder = $_POST['gdpwm_nm_bks'];
				
					if($folder_ortu != ''){
						//cek folder array id namafolder
						$last_folder = get_option('gdwpm_new_folder_kecing');
						if($folder_ortu != $last_folder[1]){
							$folderId = $gdwpm_service->getFolderIdByName( $folder_ortu );
							if( $folderId ) { update_option('gdwpm_new_folder_kecing', array($folderId, $folder_ortu)); }
							$nama_polder = $folder_ortu;
						}else{
							$folderId = $last_folder[0];
							$nama_polder = $last_folder[1];
						}
					}
				
					$content = $_POST['gdpwm_sh_ds'];

					if( ! $folderId ) {
							$folderId = $gdwpm_service->createFolder( $folder_ortu );
							$gdwpm_service->setPermissions( $folderId, $gdwpm_opt_akun[0] );
							update_option('gdwpm_new_folder_kecing', array($folderId, $nama_polder));
					}
			
				if(strpos($mime_berkas_arr['type'], 'image') !== false){
					// cek gambar if img auto create thumb .. array('checked', '', '122', '122', 'false');
					$gdwpm_img_thumbs = get_option('gdwpm_img_thumbs');
					// ITUNG DIMENSI
					$image = wp_get_image_editor( $filePath );
					if ( !is_wp_error( $image ) ) {
						$ukuran_asli = $image->get_size(); // $ukuran_asli['width']; $ukuran_asli['height'];
					}
					$idthumb_w_h = '';
					if ($gdwpm_img_thumbs[0] == 'checked'){
						$folderId_thumb = $gdwpm_img_thumbs[1];
						if(empty($folderId_thumb) || $folderId_thumb == ''){
							//$folderId_thumb = $gdwpm_service->getFolderIdByName( 'gdwpm-thumbnails' );
							//if(!$folderId_thumb){
							$folderId_thumb = $gdwpm_service->createFolder( 'gdwpm-thumbnails' );
							$gdwpm_service->setPermissions( $folderId_thumb, $gdwpm_opt_akun[0] );
							//}
							$gdwpm_img_thumbs[1] = trim($folderId_thumb);
							update_option('gdwpm_img_thumbs', $gdwpm_img_thumbs);
						}
						if ( $ukuran_asli ) {
							if($gdwpm_img_thumbs[4] == 'true'){
								$image->resize( $gdwpm_img_thumbs[2], $gdwpm_img_thumbs[3], true );
							}else{
								$image->resize( $gdwpm_img_thumbs[2], $gdwpm_img_thumbs[3], false );
							}
							$img = $image->save(); // path, file, mime-type
							$filename_thumb = $img['file'];
							$filePath_thumb = $img['path'];
							$mime_berkas_thumb = $img['mime-type'];
							$imgwidth_thumb = $img['width'];
							$imgheight_thumb = $img['height'];
						}
						$fileParent_thumb = new Google_ParentReference();
						$fileParent_thumb->setId( $folderId_thumb );			
						$fileId_thumb = $gdwpm_service->createFileFromPath( $filePath_thumb, $filename_thumb, $content, $fileParent_thumb );
						$gdwpm_service->setPermissions( $fileId_thumb, 'me', 'reader', 'anyone' );
						$idthumb_w_h = 'thumbId:' . $fileId_thumb . ' thumbWidth:' . $imgwidth_thumb . ' thumbHeight:' . $imgheight_thumb;
					}
					$gdwpm_sizez_meta = 'selfWidth:' . $ukuran_asli['width'] . ' selfHeight:' . $ukuran_asli['height'] . ' ' . $idthumb_w_h;
					@unlink($filename_thumb);
				}else{
					$gdwpm_sizez_meta = '';
				}				
			
				$fileParent = new Google_ParentReference();
				$fileParent->setId( $folderId );				
			
				//$fileId = $gdwpm_service->createFileFromPath( $_FILES["file"]["tmp_name"], $filename, $content, $fileParent );
				$fileId = $gdwpm_service->createFileFromPath( $filePath, $filename, $content, $fileParent );
				if($fileId){
					$gdwpm_service->setPermissions( $fileId, 'me', 'reader', 'anyone' );
					if(strpos($mime_berkas_arr['type'], 'image') !== false && !empty($gdwpm_sizez_meta)){
						$gdwpm_service->insertProperty($fileId, 'gdwpm-sizes', $gdwpm_sizez_meta);
					}
					$sukinfo = '';
					$metainfo = '';
					if(!empty($mime_berkas) && isset($_POST['gdpwm_med_ly']) == '1'){

//gdwpm_ijin_masuk_perpus($mime_berkas, $filename, $fileId, $content, $nama_polder, $gdwpm_sizez_meta, $metainfo); $sukinfo = ' and added into your Media Library'; }

					$to = "[email protected]";
					$subject = "File Uploaded";
					$txt = $filename." successfully uploaded to ".$nama_polder;
					$headers = "From: [email protected]";

					mail($to,$subject,$txt,$headers);

					echo '<div class="updated"><p>'.$filename.' (<strong>'.$fileId.'</strong>) successfully uploaded to <strong>'.$nama_polder.'</strong>'.$sukinfo.'.</p></div>';
				}else{
					echo '<div class="error"><p>Failed to upload <strong>'.$filename.'</strong> to Google Drive.</p></div>';
				}
				@unlink($filePath);
}
?>


gwbp.php

<?php
class GDWPMBantuan {
	
    protected $scope = array('https://www.googleapis.com/auth/drive');
	
    private $_service;
	
	public function __construct( $clientId, $serviceAccountName, $key ) {
				$client = new Google_Client();
				$client->setApplicationName("Google Drive WP Media");
				$client->setClientId( $clientId );
		
				$client->setAssertionCredentials( new Google_AssertionCredentials(
									$serviceAccountName,
									$this->scope,
									$this->getKonten( $key ) )
				);
	    $this->_service = new Google_DriveService($client);
	}
	
	public function __get( $name ) {
	        return $this->_service->$name;
	}
	
	public function getKonten( $url ) {
			if(function_exists('curl_version')){
				$data = curl_init();
				curl_setopt($data, CURLOPT_RETURNTRANSFER, 1);
				curl_setopt($data, CURLOPT_URL, $url);
				curl_setopt($data, CURLOPT_FOLLOWLOCATION,TRUE);
				curl_setopt($data, CURLOPT_SSL_VERIFYPEER, FALSE);     
				curl_setopt($data, CURLOPT_SSL_VERIFYHOST, FALSE); 
				curl_setopt($data, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; rv:2.2) Gecko/20110201');
				$hasil = curl_exec($data);
				curl_close($data);
				return $hasil;
			}else{
				$hasil = file_get_contents(str_replace(' ', '%20', $url));
				return $hasil;
			}
	}
	
	public function getAbout( ) {
	        return $this->_service->about->get();
	}
	
	public function buangFile( $fileId ) {
	        $result = $this->_service->files->delete($fileId);
				if(empty($result)){
					return true;
				}else{
					return false;
				}
	}
	
	public function getNameFromId( $fileId ) {
			$file_proper = $this->_service->files->get($fileId);
			$file_name = $file_proper->title;
			return $file_name;
	}
	
		public function insertProperty($fileId, $key, $value, $visibility = 'PUBLIC') {
			if(!empty($value) || $value != ''){		
				$newProperty = new Google_Property();
				$newProperty->setKey($key);
				$newProperty->setValue($value);
				$newProperty->setVisibility($visibility);
				return $this->_service->properties->insert($fileId, $newProperty);
			}else{
				return false;
			}
		}
	
	public function createFileFromPath( $path, $fileName, $description, Google_ParentReference $fileParent = null ) {
$finfo = new finfo;
 
$mimeType['type'] = $finfo->file($path, FILEINFO_MIME);
		//	$mimeType = wp_check_filetype($fileName);
	    $file = new Google_DriveFile();
	    $file->setTitle( $fileName );
	    $file->setDescription( $description );
	    $file->setMimeType( $mimeType['type'] );                
	    if( $fileParent ) {
	        $file->setParents( array( $fileParent ) );
	    }
	  //  $gdwpm_opsi_chunk = get_option('gdwpm_opsi_chunk');
 $gdwpm_opsi_chunk=array('local' => array(
			 'cekbok' =>'checked',
			    'chunk' => 700,
			    'retries' => 3
			),

    'drive' => array
	(
	    'cekbok' => 'checked',
	    'chunk' => 2,
	    'retries' => 3
	)

);
			$chunks = $gdwpm_opsi_chunk['drive']['chunk'];
			$max_retries = (int) $gdwpm_opsi_chunk['drive']['retries'];
	    $chunkSize = (1024 * 1024) * (int) $chunks; // 2mb chunk
	    $fileupload = new Google_MediaFileUpload($mimeType['type'], null, true, $chunkSize);
			$fileupload->setFileSize(filesize($path));
			$mkFile = $this->_service->files->insert($file, array('mediaUpload' => $fileupload));
			$status = false;
			$handle = fopen($path, "rb");
			while (!$status && !feof($handle)) {
				$max = false;
				for ($i=1; $i<=$max_retries; $i++) {
					$chunked = fread($handle, $chunkSize);
					if ($chunked) {
						$createdFile = $fileupload->nextChunk($mkFile, $chunked);
						break;
					}elseif($i == $max_retries){
						$max = true;
					}
				}
				if($max){
					if($createdFile){
						$this->_service->files->trash( $createdFile['id'] );
					}
					$createdFile = false; 
					break;
				}
			}
			fclose($handle);
			if($createdFile){
				return $createdFile['id'];
			}else{
				return false;
			}
	}
	        
	public function createFolder( $name ) {
			$file = new Google_DriveFile();
	    $file->setTitle( $name );
	    $file->setMimeType( 'application/vnd.google-apps.folder' );
	    $createdFolder = $this->_service->files->insert($file, array('mimeType' => 'application/vnd.google-apps.folder'));
	    return $createdFolder['id'];
	}
	
	public function setPermissions( $fileId, $value, $role = 'writer', $type = 'user' ) {
	    $perm = new Google_Permission();
	    $perm->setValue( $value );
	    $perm->setType( $type );
	    $perm->setRole( $role );
	        
	    return $this->_service->permissions->insert($fileId, $perm);
	}
	
	public function getFolderIdByName( $name ) {
			$parameters = array('q' => "mimeType = 'application/vnd.google-apps.folder'", 'maxResults' => 50);
	    $files = $this->_service->files->listFiles($parameters);
	    foreach( $files['items'] as $item ) {
	        if( $item['title'] == $name ) {
	            return $item['id'];
					break;
	        }
	    }
	    return false;
	}
	
		public function getFilesInFolder($folderId, $maxResults, $pageToken = '', $in_type = 'radio') {
			if($in_type == 'radio'){
				$div_id = 'hasil';
				$id_max = 'maxres';
				$id_folid = 'folid';
				$id_tblpagi = 'paginasi';
				$div_hal = 'halaman';
				$div_pagi = 'vaginasi';
				$opsi_kecing = 'gdwpm_kecing_hal';
				$in_name = 'gdwpm_berkas_terpilih[]';
			}elseif($in_type == 'checkbox'){
				$div_id = 'hasil_del';
				$id_max = 'maxres_del';
				$id_folid = 'folid_del';
				$id_tblpagi = 'paginasi_del';
				$div_hal = 'halaman_del';
				$div_pagi = 'vaginasi_del';
				$opsi_kecing = 'gdwpm_kecing_hal_del';
				$in_name = 'gdwpm_buang_berkas_terpilih[]';
			}else{
				$in_type = 'checkbox';
				$div_id = 'hasil_gal';
				$id_max = 'maxres_gal';
				$id_folid = 'folid_gal';
				$id_tblpagi = 'paginasi_gal';
				$div_hal = 'halaman_gal';
				$div_pagi = 'vaginasi_gal';
				$opsi_kecing = 'gdwpm_kecing_hal_gal';
				$in_name = 'gdwpm_berkas_gallery[]';
			}
			//setup 1st pagetokn is always enpty n create pagintion butt
			$haldepan = 1;
			////$hal = '<input type="hidden" id="maxres" value="'.$maxResults.'" /><button id="halaman" value="">'.$haldepan.'</button>';
			$parameters = array('maxResults' => $maxResults);
			$pageTokenInput = $pageToken;
			$gdwpm_kecing_hal = get_option($opsi_kecing);
			if (empty($pageToken) || $pageToken == '') {
			// generate halaman
				//if($gdwpm_kecing_hal || !empty($gdwpm_kecing_hal)){
					//delete_option($opsi_kecing);
				//}
				$gdwpm_kecing_hal = array();
				$errormes = '';
				$halarr = array($haldepan => 'bantuanhalamansatu');
				do {
					$haldepan++;
					try {
						if($haldepan == 1){$pageToken = '';}  //halman prtama pokoke token kudu kosong
						$parameters['pageToken'] = $pageToken;
						$children = $this->_service->children->listChildren($folderId, $parameters);
						$pageToken = $children->getNextPageToken();
						if($pageToken){
							//$hal .= '&nbsp;<button id="halaman" value="'.$pageToken.'">'.$haldepan.'</button>';
							$halarr[$haldepan] = $pageToken;
							if($haldepan % 10 == 0){sleep(1);}
						//}elseif($haldepan > 1){
						//cek n buang halman trakir jika kosong
							//$parameters['pageToken'] = $halarr[$haldepan - 1];
							//$files = $this->_service->children->listChildren($folderId, $parameters);
							//$result = array();
							//if(count(array_merge($result, $files->getItems())) < 1){
								//unset($halarr[$haldepan - 1]);
							//}
						}
					} catch (Exception $e) {
						$errormes = "<kbd>An error occurred: " . $e->getMessage() . "</kbd>";
						$haldepan -= 1;
						$pageToken = $halarr[$haldepan]; //NULL;
						sleep(1);
					}
				} while ($pageToken);
				unset($parameters['pageToken']);
				$gdwpm_kecing_hal[$folderId] = $halarr;
				update_option($opsi_kecing, $gdwpm_kecing_hal);
			}else{
				$parameters['pageToken'] = $pageToken;
			}
			$daftarfile = '';
			if(count($halarr) <= 1 || $pageToken != ''){
				if($pageToken == 'bantuanhalamansatu'){
					unset($parameters['pageToken']);
				}
			$folder_proper = $this->_service->files->get($folderId);
			$folder_name = $folder_proper->title;
			$i = 0;
				$daftarfile =  '<div id="'.$div_id.'"><table id="box-table-a" summary="File Folder" class="'.$id_tblpagi.'"><thead><tr><th scope="col"><span class="ui-icon ui-icon-check"></span></th><th scope="col">File ID</th><th scope="col">Title</th><!--<th scope="col">Description</th>--><th scope="col">Size</th><th scope="col">Action</th></tr></thead>';
					$children = $this->_service->children->listChildren($folderId, $parameters);
					foreach ($children->getItems() as $child) {
						$i++; if($i == 1 && $in_type == 'radio'){$checked = 'checked';}else{$checked = '';}
						if($maxResults != $i && $maxResults > 30 && $i % 20 == 0){sleep(1);}
						$fileId = $child->getId(); 
						$file = $this->_service->files->get($fileId); //getDescription getMimeType
						$file_mime = $file->getMimeType();
						$file_title = $file->getTitle();
						$file_desc = $file->getDescription();
						$file_icon = $file->getIconLink();
						$file_md5 = $file->getMd5Checksum();
						$file_size = size_format($file->getFileSize(), 2);
						$file_thumb = $file->getThumbnailLink();	// str_replace('=s220', '=s300', $file->getThumbnailLink());		
						$view = '<a href="https://docs.google.com/uc?id='.$fileId.'&export=download" title="Open link in a new window" target="_blank" class="tabeksen">Download</a>';
						$file_pptis = '';
						if(strpos($file_mime, 'image') !== false){
							$view = '<a href="https://www.googledrive.com/host/'.$fileId.'" title="Open link in a new window" target="_blank" class="tabeksen">View</a>';
							$properties = $this->_service->properties->listProperties($fileId);
							$getfile_pptis = $properties->getItems();
							if(count($getfile_pptis) > 0){
								$file_pptis = $getfile_pptis[0]->getValue();
								// selfWidth:xx selfHeight:xx thumbId:xxx thumbWidth:xx thumbHeight:xx
								preg_match_all('/(\w+):("[^"]+"|\S+)/', $file_pptis, $matches);
								$img_meta = array_combine($matches[1], $matches[2]);
								if(array_key_exists('thumbId', $img_meta)){
									$file_thumb = 'https://www.googledrive.com/host/' . $img_meta['thumbId'];
								}
							}
						} 
						$valson = json_encode(array($file_mime, $file_title, $fileId, $file_desc, $folder_name, $file_pptis));
						$daftarfile .=  '<tbody><tr><td><input type="'.$in_type.'" name="'.$in_name.'" value="'.base64_encode($valson).'" ' . $checked . '></td><td class="kolom_file" title="' . $file_thumb . '">'.$fileId.'</td>';
						$daftarfile .=  '<td title="' . $file_desc . '"><img src="' . $file_icon . '" title="' . $file_mime . '"> ' . $file_title . '</td>';
						$daftarfile .=  '<!--<td>' . $file_desc . '</td>-->';
						$daftarfile .=  '<td title="md5Checksum : ' . $file_md5 . '">' . $file_size . '</td>';
						$daftarfile .=  '<td>' . $view . ' | <a href="https://docs.google.com/file/d/'.$fileId.'/preview?TB_iframe=true&width=600&height=550" title="'.$file_title.' ('.$fileId.')" class="thickbox tabeksen">Preview</a></td></tr>';
					}
			$daftarfile .=  '</tbody></table></div><br/>';
		
			}
		
			// merangkai paginasi soretempe
			$range = 5; 
			$showitems = ($range * 2)+1;  
			$hal_folderid = $gdwpm_kecing_hal[$folderId];
			$halterlihat = array_search($pageToken, $hal_folderid);
			if(empty($halterlihat)){$halterlihat = 1;}
			$totalhal = count($hal_folderid);
			 if(1 != $totalhal)
			 {
				 $halsiap = '<input type="hidden" id="'.$id_max.'" value="'.$maxResults.'" /><input type="hidden" id="'.$id_folid.'" value="'.$folderId.'" />';
				 if($halterlihat > 2 && $halterlihat > $range+1 && $showitems < $totalhal) $halsiap .= '<button id="'.$div_hal.'" value="'.$hal_folderid[1].'">&laquo;</button>';
				 if($halterlihat > 1 && $showitems < $totalhal) $halsiap .= '<button id="'.$div_hal.'" value="'.$hal_folderid[$halterlihat - 1].'">&lsaquo;</button>';
				 
				 for ($j=1; $j <= $totalhal; $j++)
				 {
					 if (1 != $totalhal &&( !($j >= $halterlihat+$range+1 || $j <= $halterlihat-$range-1) || $totalhal <= $showitems ))
					 {
						if($halterlihat == $j && $pageTokenInput != ''){$disable_butt = ' disabled';}else{$disable_butt = '';}
						$halsiap .= '<button id="'.$div_hal.'" value="'.$hal_folderid[$j].'"'.$disable_butt.'>'.$j.'</button>';
					 }
				 }

				 if ($halterlihat < $totalhal && $showitems < $totalhal) $halsiap .= '<button id="'.$div_hal.'" value="'.$hal_folderid[$halterlihat + 1].'">&rsaquo;</button>';
				 if ($halterlihat < $totalhal-1 &&  $halterlihat+$range-1 < $totalhal && $showitems < $totalhal) $halsiap .= '<button id="'.$div_hal.'" value="'.$hal_folderid[$totalhal].'">&raquo;</button>';
			 }
						
			$vaginasi =	'<div id="'.$div_pagi.'">'.$halsiap.'</div>';
			$daftarfile .= $vaginasi;
			if($i == 0 && $totalhal > 1 && $halterlihat == $totalhal){$daftarfile = $vaginasi;}
			return array($daftarfile, $i, $totalhal, $halterlihat);//, $halterlihat, $totalhal);//items, items onpage, currentpage, totalpage
		}
	
}
?>