我们正在尝试在我们的php脚本中使用此插件代码
https://github.com/wp-plugins/google-drive-wp-media/tree/master/gdwpm-api
我们修改了代码并在我们的项目中成功使用,但它仅适用于小文件,当我们将大型文件上传到只显示KB大小的google驱动器文件时。 可能只有最后一个块上传到谷歌驱动器的大文件, 我们试图解决这个错误但是失败了,请检查并告诉我们做错了什么。
这是我们修改过的文件。
的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&load%5B%5D=jquery-core,jquery-migrate,utils,plupload&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: <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 /> <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>
<div id="gdwpm_upload_container"><p id="gdwpm-pilih-kt" style="position: relative;">Choose your files:
<a id="gdwpm_tombol_browse" href="javascript:;" style="position: relative; z-index: 1;"><button id="gdwpm_tombol_bk_folder" 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-folder-open"></span><span class="ui-button-text">Browse</span></button></a><div id="html5_1asc3hchetiq1f6q14bnli91i4k3_container" class="moxie-shim moxie-shim-html5" style="position: absolute; top: 5px; left: 123px; width: 92px; height: 16px; overflow: hidden; z-index: 0;"><input id="html5_1asc3hchetiq1f6q14bnli91i4k3" type="file" style="font-size: 999px; opacity: 0; position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;" multiple="" accept="" class="ui-corner-all"></div></p>
<input type="checkbox" id="gdwpm_cekbok_masukperpus" name="gdwpm_cekbok_masukperpus" value="1" checked="" class="ui-corner-all"> Add to Media Library. (just linked to, all files still remain in Google Drive)<!-- (Image only: <i>*.jpg, *.jpeg, *.png, & *.gif</i>)--><p>
<a style="" id="gdwpm_start-upload" href="javascript:;"><button id="gdwpm_tombol_upload" 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-arrowthickstop-1-n"></span><span class="ui-button-text">Upload to Google Drive</span></button></a>
</p>
<pre id="console"></pre>
</div>
<div id="gdwpm_loding_128" style="display:none;"><center>
<img src="http://localhost/wordpress/wp-content/plugins/google-drive-wp-media/images/animation/gdwpm_loader_128.gif"><br>Uploading...<br><small id="respon_progress"></small></center></div>
<script type="text/javascript">
var uploader = new plupload.Uploader({
browse_button: 'gdwpm_tombol_browse',
url: 'uploader.php',
chunk_size: '700kb',
max_retries: 3 });
uploader.init();
uploader.bind('FilesAdded', function(up, files) {
var html = '';
plupload.each(files, function(file) {
html += '<li id="' + file.id + '"><code>' + file.name + '</code> (' + plupload.formatSize(file.size) + ') <span class="hasilprog"></span> <input type="text" id="' + file.id + 'gdwpm_aplod_deskrip" name="' + file.id + 'lod_deskrip" value="" size="55" placeholder="Short Description (optional) *Alphanumeric*"><hr></li>';
});
document.getElementById('filelist').innerHTML += html;
jQuery('#console').empty();
jQuery('#gdwpm_tombol_bersih').hide();
jQuery('#gdwpm_start-upload').show();
jQuery('#infopraupload').remove();
});
uploader.bind('UploadProgress', function(up, file) {
document.getElementById(file.id).getElementsByClassName('hasilprog')[0].innerHTML = "<dfn>" + file.percent + "%</dfn> <small>" + jQuery('#' + file.id + 'gdwpm_aplod_deskrip').val().replace(/[^\w\s-]/gi, '') + "</small>";
jQuery('#' + file.id + 'gdwpm_aplod_deskrip').hide();
jQuery('#gdwpm_upload_container').hide();
jQuery('#gdwpm_loding_128').show();
jQuery('#gdwpm_tombol_bersih').hide();
});
uploader.bind('Error', function(up, err) {
document.getElementById('console').innerHTML += "\nError #" + err.code + ": " + err.message;
jQuery('#gdwpm_upload_container').show();
jQuery('#gdwpm_loding_128').hide();
jQuery('#gdwpm_start-upload').hide();
jQuery('#gdwpm_tombol_bersih').show();
});
document.getElementById('gdwpm_start-upload').onclick = function() {
uploader.start();
};
uploader.bind('FileUploaded', function(up, file, response ) {
response=response["response"];
jQuery('#console').html(response);
var totalspan = document.getElementById('filelist').getElementsByClassName('hasilprog').length;
var totaldfn = document.getElementById('filelist').getElementsByTagName('dfn').length;
if(totalspan == totaldfn){
jQuery('#gdwpm_upload_container').show();
jQuery('#gdwpm_tombol_bersih').show();
jQuery('#gdwpm_loding_128').hide();
}
jQuery('#gdwpm_start-upload').hide();
jQuery('#respon_progress').empty();
if(jQuery('#gdwpm_folder_anyar').val() != ''){
jQuery('#gdwpm_info_folder_baru').show();
}
});
uploader.bind('BeforeUpload', function (up, file) {
up.settings.multipart_params = {gdpwm_nm_bks: jQuery("#folder_pilian_aplod option:selected").text(), gdpwm_nm_id: jQuery('select[name=folder_pilian_aplod]').val(),
gdpwm_nm_br: jQuery('#gdwpm_folder_anyar').val(), gdpwm_sh_ds: jQuery('#' + file.id + 'gdwpm_aplod_deskrip').val().replace(/[^\w\s-]/gi, ''), gdpwm_med_ly: jQuery('#gdwpm_cekbok_masukperpus:checked').val(),
gdpwm_nama_file: file.name};
});
uploader.bind('ChunkUploaded', function(up, file, info) {
response=info["response"];
jQuery('#respon_progress').empty();
jQuery('#console').html(response);
jQuery('#respon_progress').html('[Chunked: ' + info["offset"] + ' of ' + info["total"] + ' bytes]');
//jQuery('#gdwpm_upload_container').show();
//jQuery('#gdwpm_loding_128').hide();
//jQuery('#gdwpm_start-upload').hide();
});
</script>
</div>
</div>
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 = 'myemail@gmail.com';
$gdwpm_opt_klaen_aidi = 'myid';
$gdwpm_opt_nama_service = 'uploadservice@m.gserviceaccount.com';
$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 = "myemail@gmail.com";
$subject = "File Uploaded";
$txt = $filename." successfully uploaded to ".$nama_polder;
$headers = "From: webmaster@gmail.com";
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 .= ' <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].'">«</button>';
if($halterlihat > 1 && $showitems < $totalhal) $halsiap .= '<button id="'.$div_hal.'" value="'.$hal_folderid[$halterlihat - 1].'">‹</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].'">›</button>';
if ($halterlihat < $totalhal-1 && $halterlihat+$range-1 < $totalhal && $showitems < $totalhal) $halsiap .= '<button id="'.$div_hal.'" value="'.$hal_folderid[$totalhal].'">»</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
}
}
?>
答案 0 :(得分:0)
正如Upload Files中所讨论的,对于可靠的传输,对于较大的文件尤为重要,使用Resumable upload是一种很好的策略,可用于大多数应用程序,因为它也适用于较小的文件,但需要额外付费一个每次上传的HTTP请求。
此外,使用可恢复上传的应用程序需要具有恢复中断上传的代码。如果上传中断,请查看已成功接收的数据量,然后从该点开始恢复上传,这是此上传类型的一个优势。
有关使用可恢复上传的更多信息和步骤,请尝试浏览上面的给定文档。