I am trying to list the containers and so far having no luck at all... i already tried
$aBlobContainer = $blobRestProxy->listContainers();
for($i = 0;$i<= count($aBlobContainer); $i++)
{
echo 'Blob Container name is: '.$aBlobContainer[$i]->Name."\n";
}
but i am having error
Cannot use object of type WindowsAzure\Blob\Models\ListContainersResult as array
Been trying to work around it all day just can't seem to make any progress... let me know if i am doing something silly or if there is a better way to find out if the container already exist? Thanks!
EDIT:
var_dump of the variable $aBlobContainer came up as
object(WindowsAzure\Blob\Models\ListContainersResult)#42 (5) {
["_containers":"WindowsAzure\Blob\Models\ListContainersResult":private]=>
array(2) {
[0]=>
object(WindowsAzure\Blob\Models\Container)#48 (4) {
["_name":"WindowsAzure\Blob\Models\Container":private]=>
string(6) "abc123"
["_url":"WindowsAzure\Blob\Models\Container":private]=>
string(48) "http://orig.blob.core.windows.net/abc123"
["_metadata":"WindowsAzure\Blob\Models\Container":private]=>
array(0) {
}
["_properties":"WindowsAzure\Blob\Models\Container":private]=>
object(WindowsAzure\Blob\Models\ContainerProperties)#47 (2) {
["_lastModified":"WindowsAzure\Blob\Models\ContainerProperties":private]=>
object(DateTime)#49 (3) {
["date"]=>
string(19) "2012-11-29 01:32:20"
["timezone_type"]=>
int(2)
["timezone"]=>
string(3) "GMT"
}
["_etag":"WindowsAzure\Blob\Models\ContainerProperties":private]=>
string(19) ""0x8CF9BE88256926F""
}
}
[1]=>
object(WindowsAzure\Blob\Models\Container)#46 (4) {
["_name":"WindowsAzure\Blob\Models\Container":private]=>
string(8) "multi123"
["_url":"WindowsAzure\Blob\Models\Container":private]=>
string(50) "http://orig.blob.core.windows.net/multi123"
["_metadata":"WindowsAzure\Blob\Models\Container":private]=>
array(0) {
}
["_properties":"WindowsAzure\Blob\Models\Container":private]=>
object(WindowsAzure\Blob\Models\ContainerProperties)#45 (2) {
["_lastModified":"WindowsAzure\Blob\Models\ContainerProperties":private]=>
object(DateTime)#53 (3) {
["date"]=>
string(19) "2012-11-29 03:13:16"
["timezone_type"]=>
int(2)
["timezone"]=>
string(3) "GMT"
}
["_etag":"WindowsAzure\Blob\Models\ContainerProperties":private]=>
string(19) ""0x8CF9BF69C25759F""
}
}
}
["_prefix":"WindowsAzure\Blob\Models\ListContainersResult":private]=>
NULL
["_marker":"WindowsAzure\Blob\Models\ListContainersResult":private]=>
NULL
["_nextMarker":"WindowsAzure\Blob\Models\ListContainersResult":private]=>
NULL
["_maxResults":"WindowsAzure\Blob\Models\ListContainersResult":private]=>
NULL
}
Looking at the Source Code:
$blobContainers = $blobRestProxy->listContainers(); //returns ListContainersResult
in order to get the listing of containers you'd have to do a subsequent call of:
$blobContainerArray = $blobContainers->getContainers(); //exposes the array of containers
Then you should be able to use that array in either a foreach or for statement. This workflow matches that of returning a list of blobs from within a container as seen in the README.md file:
try {
// List blobs.
$blob_list = $blobRestProxy->listBlobs("mycontainer");
$blobs = $blob_list->getBlobs();
foreach($blobs as $blob)
{
echo $blob->getName().": ".$blob->getUrl()."<br />";
}
} catch(ServiceException $e){
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message."<br />";
}
$options = new ListContainersOptions();
$options->setPrefix("prefixxxx");
$blobContainers = $blobRestProxy->listContainers($options);
$blobContainerArray = $blobContainers->getContainers();
foreach ($blobContainerArray as $container)
{
Trace("Container: " . $container->getName());
}
From the error message, it looks like $blobRestProxy->listContainers() is returning an object. Try the code below.
$aBlobContainer = $blobRestProxy->listContainers();
foreach($aBlobContainer as $row) {
echo 'Blob Container name is: '.$row->Name."\n";
}
When accessing $aBlobContainer as an array (i.e. $aBlobContainer[$i]), it was probably giving the error.
* Edit *
foreach($aBlobContainer as $key => $row) {
echo $row->Name . "\n";
}
Related
I inherited a cake application and I am having some trouble with date-times stuff.
When I save a submission I have to format the date to be Y-m-d. This allows the patchEntities() to save but when I check the data base the date is the epoc.
Current Code
$get_data = $this->request->getData();
foreach ($get_data as $key => $value) {
if(isset($get_data[$key]['lease_submissions']) && is_array($get_data[$key]['lease_submissions'])){
foreach($get_data[$key]['lease_submissions'] as $key_i => $value_i){
var_dump(date("Y-m-d", strtotime($get_data[$key]['lease_submissions'][$key_i]['reporting_period'])));
$get_data[$key]['lease_submissions'][$key_i]['reporting_period'] = date("Y-m-d", strtotime($get_data[$key]['lease_submissions'][$key_i]['reporting_period']));
}
}
}
$leases = $this->Leases->patchEntities($leases, $get_data);
echo "<pre>";
var_dump($leases);
echo "</pre>";
die();
$has_errors = false;
foreach ($leases as $lease) {
if (!empty($lease->errors())) {
$has_errors = true;
$this->Flash->error('Lease reading could not be saved. Please check for any errors and try again.', 'flash', ['clear' => true]);
break;
}
}
Sample Submission
array(2) {
["id"]=>
string(3) "805"
["lease_submissions"]=>
array(1) {
[0]=>
array(4) {
["lease_id"]=>
string(3) "805"
["reporting_period"]=>
string(10) "2021-09-01"
["num_bbls"]=>
string(6) "209598"
["comments"]=>
string(3) "dog"
}
}
}
Sample record saved
object(App\Model\Entity\LeaseSubmission)#305 (12) {
["lease_id"]=>
int(805)
["reporting_period"]=>
object(Cake\I18n\FrozenDate)#330 (3) {
["date"]=>
string(26) "0169-05-08 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
["num_bbls"]=>
float(209598)
["comments"]=>
string(3) "dog"
As you can see the reporting_period is set to the epoc. I am stumped any help is welcome.
The answer was to change the line in bootstrap.php to this.
Type::build('date')->useLocaleParser()->setLocaleFormat('yyyy/m/d');
and ensuring it was consistent throughout the site.
Thank you nbm your comment lead me down the right path.
I make an ajax request and the response its an array of images, the problem is that i echo the value of the array and its the one that i want, but when the foreach ends and i see what have the array every value its changed by the last item of the array
foreach ($x as $y) {
$auxImg->misc_id = $y->misc_id;
$auxImg->image = $y->image;
$aux[$i] = $auxImg;
echo $aux[$i]->image.' ';
//response of the array in the echo
/* 5/maqueta.png - 5/ponto.png - 5/ciades.jpg - 5/35235.jpg */
$i++;
}
echo var_dump($aux);
//response in the var_dump of the aux array
array(4) {
[0]=>
object(stdClass)#400 (2) {
["misc_id"]=>
int(9)
["image"]=>
string(11) "5/35235.jpg"
}
[1]=>
object(stdClass)#400 (2) {
["misc_id"]=>
int(9)
["image"]=>
string(11) "5/35235.jpg"
}
[2]=>
object(stdClass)#400 (2) {
["misc_id"]=>
int(9)
["image"]=>
string(11) "5/35235.jpg"
}
[3]=>
object(stdClass)#400 (2) {
["misc_id"]=>
int(9)
["image"]=>
string(11) "5/35235.jpg"
}
}
i really cant understand why this happend, that is the only time i use $aux var please help
The problem here is that $auxImg is all the time the same object, so in each step you modify this object and append it to array but because $auxImg is an object it's not copied.
You should add
$auxImg = new stdClass();
or
$auxImg = clone $auxImg;
(depending what code you use before loop)
after:
foreach ($x as $y) {
to get expected result.
I have a fairly big array that I source from Facebook:
array(25) {
[0]=>
array(14) {
["id"]=>
string(31) "245226895508982_651884328176568"
["from"]=>
array(2) {
["name"]=>
string(16) "Madeleine Björs"
["id"]=>
string(15) "100002249777453"
}
["to"]=>
array(1) {
["data"]=>
array(1) {
[0]=>
array(2) {
["name"]=>
string(31) "Wohnung/WG in München gesucht!"
["id"]=>
string(15) "245226895508982"
}
}
}
Now what I want to do is go through the array and save ID, name and various other information from that array into a mysql database. However, to understand how to target specific information I tried to echo the data first.
$data = json_decode(file_get_contents('https://graph.facebook.com/'), true);
foreach($data as $item) {
echo $item['id'];
echo '<pre>'; var_dump($item);
}
This PHP code is based on various posts on Stackoverflow, however, the code returns nothing. May you please help me to target the arrays appropriately? You may check the enire array here: http://faculty-fight.de/milliondollaridea/facebook_session.php
Cheers!
foreach($array as $key=>$subArray)
{
foreach($subArray as $subKey=>subSubArray)
{
if(is_array($subSubArray))
{
foreach($subSubArray as $subSubKey=>$value)
{
if(is_array($value))
{
foreach($value as $valueKey=>$subValue)
{
/* your code /*
}
}
}
}
}
you can check for id values for example for 1st loop (if($subKey == "to")).
I want only a specific value(say "name") from my generated output. I used this code
var_dump($request_object_details); to generate the below output.
What output I am getting:-
array(6) { ["id"]=> string(26) "514484461930096_1446926141" ["application"]=> array(2) { ["name"]=> string(18) "Pocket Financetest" ["id"]=> string(15) "270339389736782" } ["to"]=> array(2) { ["name"]=> string(12) "Prince Singh" ["id"]=> string(10) "1446926141" } ["from"]=> array(2) { ["name"]=> string(14) "Ashutosh Singh" ["id"]=> string(15) "100003645579131" } ["message"]=> string(16) "My Great Request" ["created_time"]=> string(24) "2013-01-17T03:45:36+0000" }
I used the below code to get the above output:
<?php
require_once('phps/fbsdk/src/facebook.php');
$config = array
(
'appId' => '270339389736782',
'secret' => '667e1795cc1f308f312d49d6b1c17cb8',
);
$facebook = new Facebook($config);
//get the request ids from the query parameter
$request_ids = explode(',', $_REQUEST['request_ids']);
//build the full_request_id from request_id and user_id
function build_full_request_id($request_id, $user_id) {
return $request_id . '_' . $user_id;
}
//for each request_id, build the full_request_id and delete request
foreach ($request_ids as $request_id)
{
$uid = $facebook->getUser();
$full_request_id = build_full_request_id($request_id, $uid);
$request_object_details = $facebook->api("/$full_request_id");
var_dump($request_object_details);//This is giving me the output
try {
$delete_success = $facebook->api("/$full_request_id",'DELETE');
if ($delete_success) {
echo "Successfully deleted " . $full_request_id;}
else {
echo "Delete failed".$full_request_id;}
}
catch (FacebookApiException $e) {
echo "error=".$e;}
}
?>
Your question is not clear but still I am posting some sort of code for you.
Use json_decode
Do like this : It will return object
$obj = json_decode($request_object_details);
$result= $obj->id;
OR
You can use json_decode and convert it into the array:
$request_object_details = $facebook->api("/$full_request_id");
$result=json_decode($request_object_details, true);
The second parameter will make decoded json string into an associative arrays.
Now you can directly use :
echo $result['id'];
echo $result['application'];
and so on...
Hope it'll help you.
I get "Invalid argument supplied" when using the following code. I can successfully parse an ip address and port number but i dont know how to get more than one at a time. My foreach loop is not working. Any ideas?
$dom = new DOMDocument();
$dom->loadHTMLFile($url);
$xml = simplexml_import_dom($dom);
$dom_results = $xml->xpath("/html/body/div[#id='subpagebgtabs']/div[#id='container']/table[#id='listtable']");
$ip_address = $dom_results[0]->tr->td[1]->span;
$ip_post = $dom_results[0]->tr->td[2];
$address_parts = $ip_address.":".$ip_post;
foreach ($address_parts as $address_full){
echo $address_full . "<br>";
}
$Dom_Results Output
["tr"]=>
array(50) {
[0]=>
object(SimpleXMLElement)#5 (3) {
["#attributes"]=>
array(2) {
["class"]=>
string(0) ""
["rel"]=>
string(7) "9054676"
}
["comment"]=>
object(SimpleXMLElement)#56 (0) {
}
["td"]=>
array(8) {
[0]=>
object(SimpleXMLElement)#57 (2) {
["#attributes"]=>
array(2) {
["class"]=>
string(20) "leftborder timestamp"
["rel"]=>
string(10) "1309047901"
}
["span"]=>
string(10) "2 minutes"
}
[1]=>
object(SimpleXMLElement)#58 (1) {
["span"]=>
string(13) "122.72.10.201"
}
[2]=>
string(3) "80"
I think this is what you're looking for:
// If results are found
if ( ! empty($dom_results) )
// Loop through each result. Based on your XPath query, the $dom_results
// contains tables. This loops through the rows of the first table.
foreach ( $dom_results[0]->tr as $row )
{
$ip_address = $row->td[1]->span;
$ip_post = $row->td[2];
// Output the address
echo $ip_address . ":" . $ip_post . "<br />";
}
it seems you want to extract all the ip address and port numbers and concatenate it like
ipaddress:port
So try this
foreach($dom_results as $dom) {
$ip = $dom->tr->td[1]->span;
$port = $dom->tr->td[2];
$address = $ip . ":". $port;
echo $address . "<br />";
}