2012-04-18 121 views
0

我需要使用ACL顯示視頻/圖像文件:在我的wordpress博客上,PRIVATE上傳到我的Amazon S3帳戶。從亞馬遜S3流式傳輸私人視頻

我是基於PHP oops的編碼的新手。任何腳本的幫助,鏈接參考,免費插件,甚至邏輯算法將是很大的幫助:)

在此先感謝。

+2

您可以先看一下PHP的SDK:http://aws.amazon.com/sdkforphp/另外通過代碼示例,它們非常有用。 – alxbrd 2012-04-18 14:24:00

回答

2

這個問題可以通過實施以下步驟來解決:從here

  • SDK的

    1. 下載最新的穩定版本解壓.zip文件&發生在wamp/www文件夾
    2. 重命名配置樣本。 inc.php文件到config.inc.php
    3. 添加訪問密鑰&密鑰成上述文件(從Amazon S3帳戶檢索),保存&出口
    4. 創建一個示例文件以從Amazon S3

    文件應如下所述的內容顯示公共/私有對象如下:

    require('sdk.class.php'); 
    require('services/s3.class.php'); 
    
    $s3 = new AmazonS3(); 
    $bucket = "bucketname"; 
    $temp_link = $s3->get_object_url($bucket, 'your/folder/path/img.jpg', '5 minute'); 
    
    echo $temp_link; 
    

    在上面的代碼中,您作爲輸出接收到的URL是私有對象的簽名URL,因此它僅在5分鐘內有效。

    您可以授予未來日期的訪問權限,並且只允許授權用戶訪問您在Amazon S3上的私人內容或媒體。

  • 1

    這個問題有點老了,但我仍然發佈它。今天我有一個類似的問題,發現有一個簡單的答案。

    aws doc解釋清楚,並有一個例子。

    http://docs.aws.amazon.com/aws-sdk-php-2/guide/latest/service-s3.html#amazon-s3-stream-wrapper

    基本上,需要註冊AWS」流封包和使用S3://協議。

    這是我的代碼示例。

    use Aws\Common\Aws; 
    use Aws\S3\Enum\CannedAcl; 
    use Aws\S3\Exception\S3Exception; 
    
    $s3 = Aws::factory(array(
        'key' => Config::get('aws.key'), 
        'secret' => Config::get('aws.secret'), 
        'region' => Config::get('aws.region') 
    ))->get('s3'); 
    
    $s3->registerStreamWrapper(); 
    
    // now read file from s3 
    // from the doc. 
    
    // Open a stream in read-only mode 
    if ($stream = fopen('s3://bucket/key', 'r')) { 
        // While the stream is still open 
        while (!feof($stream)) { 
         // Read 1024 bytes from the stream 
         echo fread($stream, 1024); 
        } 
        // Be sure to close the stream resource when you're done with it 
        fclose($stream); 
    }