Currently, I am using plupload.js to upload files to google drive using Google Drive API. But, I can't upload a bigger file that is configured in php.ini upload_max_filesize.
I am getting the below error:
The uploaded file exceeds the upload_max_filesize directive in php.ini
Is there any way to skip the server upload_max_filesize limitation to upload files to Google Drive using the Google Drive PHP SDK API?
$file = $files['file'];
try {
$this->client->setDefer( true );
$params = [
'fields' => '*',
'supportsAllDrives' => true,
'enforceSingleParent' => true
];
$parent_id = ! empty( $folder['id'] ) ? $folder['id'] : $folder;
$request = $this->service->files->create( new \IGDGoogle_Service_Drive_DriveFile( [
'name' => $file['name'],
'parents' => [ $parent_id ],
'mimeType' => $file['type']
] ), $params );
$chunk_size_bytes = 5 * 1024 * 1024;
$media = new \IGDGoogle_Http_MediaFileUpload( $this->client, $request, $file['type'], null, true, $chunk_size_bytes );
$media->setFileSize( $file['size'] );
$status = false;
$upload_status = [
'url' => $media->getResumeUri(),
'size_uploaded' => 0,
'percent' => 0,
];
$fileHandler = fopen( $file['tmp_name'], 'rb' );
while ( ! $status and ! feof( $fileHandler ) ) {
$chunk = fread( $fileHandler, $chunk_size_bytes );
$status = $media->nextChunk( $chunk );
$upload_status['size_uploaded'] += strlen( $chunk );
$upload_status['percent'] = round( ( $upload_status['size_uploaded'] / $file['size'] ) * 100 );
// Update the upload status
set_transient( 'igd_upload_' . $file_id, $upload_status, HOUR_IN_SECONDS );
}
fclose( $fileHandler );
$this->client->setDefer( false );
if ( $status ) {
$file = igd_file_map( $status );
Files::instance()->add_file( $file, $parent_id );
// Delete upload status
//delete_transient( 'igd_upload_' . $file_id );
return [
'success' => true,
'file' => $file,
];
}
} catch ( \Exception $exception ) {
return [
'error' => $exception->getMessage(),
];
}