我正在使用 PHP 和 AWS SDK v3 处理一个项目,我必须通过传递文件名来检查文件是否已经存在。这是我尝试过的:从HTML 模板:<html> <form id="form" action="check_existing.php" method="post"> <input type="text" name="fName" > <input type="submit" name="submit" value="Submit"><br /> </form></html>来自check_existing.php:include 'create_client.php';if(isset($_POST["submit"])){ $filename = $_POST['fName']; $info = $s3->doesObjectExist($bucketName, $filename); print($info); if ($info) { echo 'File exists'; } else { echo 'File does not exists'; }}这是我创建s3客户端的方式:$s3 = new Aws\S3\S3Client([ 'region' => $region, 'version' => 'latest', 'credentials' => [ 'key' => $IAM_KEY, 'secret' => $IAM_SECRET, ],]);问题: 它总是返回File does not exists
2 回答
开心每一天1111
TA贡献1836条经验 获得超13个赞
$s3 = new S3($s3_accesskey, $s3_secretkey); //create s3 object
$info = $s3->getObjectInfo($s3_bucket, $filename); // $filename can be path of file in bucket
if ($info){
echo 'File exists';
}else{
echo 'File does not exists';
}
getObjectInfo() 返回信息如下
Array
(
[date] => 1596690179
[time] => 1596651169
[hash] => 1234c1234341a7f2565c108b23b4aaca
[type] => image/jpeg
[size] => 18968
)
大话西游666
TA贡献1817条经验 获得超14个赞
$s3 = new AmazonS3();
$bucket = 'your-bucket' . strtolower($s3->key);
$test = $s3->doesObjectExist($bucket, 'testfile.jpg');
// Success or not? (Boolean, not a CFResponse object)
var_dump($test); // it will return boolean
- 2 回答
- 0 关注
- 186 浏览
添加回答
举报
0/150
提交
取消