开发者

How to delete from S3

I have a PHP file upload script for putting documents onto S3, so far the User can delete the file from the SQL list but not from S3 directly. Is they a simple way I can add the delete from S3 into the same code as below

The rest of the php script includes the s3.php if that helps

$bucket = 'files';
$path = 'file/'; // Can be empty ''
if (isset($_GET['id']))
{
    $id = $_GET['id'];
    $path .= 'File'.$id.'/';
    if (isset($_GET['action']))
    {
        $action = $_GET['action'];
        if ($action = "deleteFile")
        {
            $Fileid = $_GET['Fileid'];
            $query = "DELETE FROM amazon_upload WHERE Upload_F开发者_运维技巧ile_Id='".$Fileid."'";
            $result = mysql_query($query);
            if (!$result)
            {
                die ("could not query database: <br />".mysql_error());
            }
            $locationHeader = "Location: http://www.website.com/upload.php?id=".$id;
            header($locationHeader);
        }
    }
}


this works well

$s3 = new AmazonS3();

$bucket = 'velobucket';
$folder = 'mydirectory/';

$response = $s3->get_object_list($bucket, array(
   'prefix' => $folder
));

foreach ($response as $v) {
    $s3->delete_object($bucket, $v);
}


Try With

unlink()

E.G

$file = "test.txt";
if (!unlink($file))
  {
  echo ("Error deleting $file");
  }
else
  {
  echo ("Deleted $file");
  }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜