Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在谷歌云存储中存储wordpress媒体_Wordpress_Google Cloud Storage - Fatal编程技术网

如何在谷歌云存储中存储wordpress媒体

如何在谷歌云存储中存储wordpress媒体,wordpress,google-cloud-storage,Wordpress,Google Cloud Storage,我有一台运行wordpress站点的Linode服务器,/wp content/uploads中的媒体越来越大,填满了我的服务器SSD驱动器。所以我想把它转移到谷歌云存储 我有签出WP2CLOUD,但需要ClouSE wich,它不支持MySQL服务器5.1.73-1。我使用linux 2.6.32-5-amd64运行Debian。首先,您需要创建一个bucketex.cloud.my domain.com 得到 关于如何进行身份验证,已经有很多例子了 Wordpress 我已禁用选项将上传

我有一台运行wordpress站点的Linode服务器,/wp content/uploads中的媒体越来越大,填满了我的服务器SSD驱动器。所以我想把它转移到谷歌云存储


我有签出WP2CLOUD,但需要ClouSE wich,它不支持MySQL服务器5.1.73-1。我使用linux 2.6.32-5-amd64运行Debian。

首先,您需要创建一个bucket
ex.cloud.my domain.com


得到

关于如何进行身份验证,已经有很多例子了

Wordpress
我已禁用选项
将上传内容组织到基于月份和年份的文件夹中
,因此在图像上传到存储器后,每次上传都会清除wp上传。

看来(WordPress插件)可能是一个完美的解决方案
它允许您

  • 将整个网站数据放到云存储中
  • 仅将媒体文件上载到云存储
  • 在运行WordPress的Web服务器上的uploads文件夹中存储媒体文件时,仅将网站内容迁移到云存储

支持Amazon S3和Google云存储

如果您希望将WordPress媒体文件上载到Google云存储,请安装。它是免费的,我在我所有的客户WordPress网站上运行它。

WP2Cloud不再工作了。
// 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;
}