我有一个运行wordpress网站的Linode服务器,/ wp-content /中的媒体上传它变得越来越大并填满我的服务器SSD驱动器。所以我想将其转移到Google云端存储。
我有结账WP2CLOUD但要求ClouSE不支持MySQL服务器5.1.73-1。我用linux 2.6.32-5-amd64运行Debian。
答案 0 :(得分:1)
如果您要将WordPress媒体文件上传到Google云端存储,请安装WP-Stateless plugin。它是免费的,我在我的所有客户端WordPress网站上运行它。
答案 1 :(得分:0)
似乎WP2Cloud(WordPress插件)可能是一个完美的解决方案。
它允许你
支持Amazon S3和Google Cloud Storage
答案 2 :(得分:-1)
首先,您需要创建一个存储桶ex. cloud.my-domain.com
。
有很多关于如何进行身份验证的例子。
// Run this function on every image upload
add_action('wp_handle_upload', 'process_images');
function process_images($results) {
if( $results['type'] === 'image/jpeg' || $results['type'] === 'image/png' || $results['type'] === 'image/gif' ) {
$imgfilename = $results[ 'file' ];
$imgurl = $results[ 'url' ];
if ( ! is_wp_error( $theme_image ) ) {
$imageName = wp_basename($imgurl);
// Save image to cloud storage
saveToStorage($imgurl, $imageName, $results['type']);
}
return $results;
}
}
function saveToStorage($url, $imageName, $type){
$objects = callGoogleClient();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$imgData = curl_exec($ch);
$postbody = array('mimeType' => $type, "data" => $imgData);
$gso = new Google_StorageObject();
$gso->setName(A_CLOUD_FOLDER.'/'.$imageName);
$resp = $objects->insert(MY_BUCKET, $gso, $postbody);
}
// Delete an image from cloud storage
add_filter('wp_delete_file', 'on_remove_file');
function on_remove_file($file) {
$objects = callGoogleClient();
$name = wp_basename($file);
$resp = $objects->delete(MY_BUCKET, A_CLOUD_FOLDER.'/'. $name);
return $file;
}
function callGoogleClient(){
$client = new Google_Client();
$client->setClientId('your_id.apps.googleusercontent.com');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, KEY_FILE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$key = curl_exec($ch);
$client->setClientId(CLIENT_ID);
$client->setAssertionCredentials(new Google_AssertionCredentials(
SERVICE_ACCOUNT_NAME,
array('https://www.googleapis.com/auth/devstorage.full_control'),
$key)
);
$StorageService = new Google_StorageService($client);
$objects = $StorageService->objects;
return $objects;
}
我已禁用选项Organize my uploads into month- and year-based folders
因此,在将图像上传到存储空间后,每次上传都会清除wp-upload get。