我可以上傳文件到谷歌與此代碼驅動該(大小< 100 MB)
但對於較大的文件顯示此錯誤:
上傳大文件到Google雲端硬盤(PHP谷歌驅動API)
Fatal error: Out of memory (allocated 2359296) (tried to allocate 300457543 bytes) in /home/bahmanx2/public_html/gd/index.php on line 40
我代碼是
<?php
ini_set('memory_limit', '-1');
ini_set('upload_max_filesize', '1000M');
ini_set('post_max_size', '1000M');
ini_set('max_input_time', 3000);
ini_set('max_execution_time', 3000);
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_DriveService.php';
$client = new Google_Client();
$client->setClientId('Client Id');
$client->setClientSecret('Client Secret');
$client->setRedirectUri('Redirect Uri');
$client->setScopes(array('https://www.googleapis.com/auth/drive'));
$service = new Google_DriveService($client);
if (isset($_GET['logout'])) { // logout: destroy token
unset($_SESSION['token']);
die('Logged out.');
}
if (isset($_GET['code'])) { // we received the positive auth callback, get the token and store it in session
$client->authenticate();
$_SESSION['token'] = $client->getAccessToken();
}
if (isset($_SESSION['token'])) { // extract token from session and configure client
$token = $_SESSION['token'];
$client->setAccessToken($token);
}
if (!$client->getAccessToken()) { // auth call to google
$authUrl = $client->createAuthUrl();
header("Location: ".$authUrl);
die;
}
//Insert a file
$file = new Google_DriveFile();
$file->setTitle('My file');
$file->setDescription('A test file');
$file->setMimeType('application/x-rar-compressed');
$data = file_get_contents('file.rar'); // 287 MB
$createdFile = $service->files->insert($file, array(
'data' => $data,
'mimeType' => 'text/plain',
));
print_r($createdFile);
?>
如何解決這個錯誤?
我可以使用chuncked或捲曲下載文件到我的服務器,但如何上傳大文件到谷歌驅動器?
什麼是PHP的版本,什麼是你運行的機器和os /內存/網絡服務器?看起來像它限制你分配內存2.25mb,而你試圖分配~300mb。 –
我的cPanel php版本是5.3。內存限制在php.ini中的大小是128MB.I可以上傳大小低於100MB的文件。我搜索谷歌和使用ini_set,我寫的代碼頂部,但問題沒有解決 – user2511140