2011-04-11 24 views
0

我的用戶可以通過編程方式將圖像上傳到AWS S3存儲桶。但使用相同的PHP S3類包括(其中包含看跌的情況下以及本刪除情況如下) - 他們無法刪除文件:可以編程方式將其分配給Amazon S3存儲桶但不能刪除

 case 'DELETE': 
      curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE'); 
     break; 

所以我想知道如果任何在那裏可以看到我在劇本中缺少的東西。我沒有收到任何錯誤消息。 -Thanks

//THIS WORKS 

       //include the S3 class 
      if (!class_exists('S3'))require_once('S3.php'); 

    //GET keys 
    include_once "scripts/S3k.php"; 


//instantiate the class 
$s3 = new S3(awsAccessKey, awsSecretKey);  

    //assigns file location var to get 
    $fileTempName = $DestinationFile; 
    //Assigns S3 path/file name 
    $fileName = $path.$user_id."/".$fileName; 

//Move the file over to S3 
    if ($s3->putObjectFile($fileTempName, $mybucket, $fileName, S3::ACL_PUBLIC_READ)) { 
    echo " file uploaded"; 
}    


//THIS doesn't WORKS 

//include the S3 class 
if (!class_exists('S3'))require('S3.php'); 

//get KEYS 
include "scripts/S3k.php"; 

//instantiate the class 
    $s3 = new S3(awsAccessKey, awsSecretKey);  

//Assigns S3 path/file name 
    $fileName = $path.$user_id."/".$image_link; 

//Deletes the file in S3 
    if ($s3->deleteObject($mybucket, $fileName)) { 
    echo "Deleted file."; 
}    

//And this GET script doesn't work either. 
    $image_link = "1/Bowery_3_58x46app.jpg"; 
    $pathS3 = "http://d21v2uajc20x0x.cloudfront.net/myGallerist/artWorkImages/"; 

//include the S3 class 
if (!class_exists('S3'))require_once('S3.php'); 

include_once "scripts/S3k.php"; 

//instantiate the class 
$s3 = new S3(awsAccessKey, awsSecretKey);  

// Get the file from S3 

    if ($s3->getObject($mybucket, $pathS3.$image_link, "tempImage/".$image_link)) {   

     } else { 

      // Couldn't move the file over. 
      $msgToUser = 'No file was uploaded.'; 
    } 
+0

請將您在S3響應中收到的錯誤消息發佈到您的DELETE請求中。 – 2011-04-11 23:04:05

回答

1

我可能是錯的,但看起來它可能是與鬥名稱的問題,在刪除您使用的是可變的,其中在放對象已硬編碼桶名稱bucketname,可以請確認變量是否包含正確的存儲桶名稱?

編輯: 你也應該嘗試在兩種情況下回顯$ fileName,並確保它們完全相同。

+0

感謝您的回覆。不,這些水桶名稱都是「手機」。認爲最好用這個問題的替代品取而代之,我只是錯誤地替換了其中一個。 – artworthy 2011-04-12 12:47:13

+0

以及$ fileName。那些是正確的?另外請發佈你刪除的S3錯誤。 – 2011-04-12 12:49:53

+0

是的,$ fileName檢出。與PUT腳本相同的設置。沒有錯誤信息。我剛剛添加了一個getObject腳本,該腳本也沒有錯誤消息。 - 謝謝,艾倫 – artworthy 2011-04-12 15:29:44