Jump to content

Preventing a warning message from showing


galvin

Recommended Posts

I hope this is enough info, but I have this code (at the bottom) that grabs images from my S3 account (Amazon Web Services)... If there is no bucket for the name given, it gives this warning...

 

Warning: S3::getBucket(): [NoSuchBucket] The specified bucket does not exist in /home/xxxxxxx/public_html/xxxxxxx.com/S3.php on line 126

 

Assuming it's not specific syntax to S3 and is general PHP syntax, how could I prevent that warning from showing, by saying in plain English "If a bucket by that name doesn't exist, I'm gonna do something else and NOT spit out this warning?"

 

Basically, I want to echo a message like "There is no bucket yet" instead of having that ugly warning.

 

 

// Get the contents of our bucket
$contents = $s3->getBucket("mybucket");
foreach ($contents as $file){

	$fname = $file['name'];
	$furl = "http://mybucket.s3.amazonaws.com/".$fname;

	//output a link to the file
	echo "<a href=\"$furl\">$fname</a><br />";
	echo "<img src='$furl' width='50' /><br />";
	echo "$furl<br />";

}

Link to comment
Share on other sites

Generally functions or methods should return either true or false depending on wether or not they fail or succeed. This makes them easy to handle using logic like:

 

if ($contents = $s3->getBucket("mybucket")) {
  foreach ($contents as $file) {
    // rst of code
  }
}

 

Clearly, whatever $s3 is pretty poorly written as it appears to be triggering a warning. I would investigate the getBucket() method itself and have it either return true or false, or if really necessary an exception. At least they are easy to handle.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.