我的用户可以将图像以编程方式上传到AWS S3存储桶。但是使用相同的php S3类include(其中包含 put case 以及下面的 delete case ) - 它们无法删除文件:
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 :(得分:1)
我可能错了但似乎它可能是存储桶名称的问题,在删除时您使用变量作为存储桶名称,因为在put对象中您已对存储桶名称进行了硬编码,请您验证该变量包含正确的存储桶名称?
编辑: 此外,您应该尝试在两种情况下回显$ fileName并确保它们完全相同。