I am printing out a structure
$structure = imap_fetchstructure($imap, $email_number);
print_r($structure);
I need to look inside the array and get [disposition] tag of my inline attachment.
I am trying out using:
$inline_attachment = $structure[1]->disposition;
if($inline_attachment == inline){
echo "inline attachment found!!";
}
stdClass Object (
[type] => 1
[encoding] => 0
[ifsubtype] => 1
[subtype] => RELATED
[ifdescription] => 0
[ifid] => 0
[ifdisposition] => 0
[ifdparameters] => 0
[ifparameters] => 1
[parameters] => Array
(
[0] => stdClass Object
(
[attribute] => boundary
[value] => 047d7b624dd8b40cbc05172d65ae
)
)
[parts] => Array
(
[0] => stdClass Object
(
[type] => 1
[encoding] => 0
[ifsubtype] => 1
[subtype] => ALTERNATIVE
[ifdescription] => 0
[ifid] => 0
[ifdisposition] => 0
[ifdparameters] => 0
[ifparameters] => 1
[parameters] => Array
(
[0] => stdClass Object
(
[attribute] => boundary
[value] => 047d7b624dd8b40cb805172d65ad
)
)
[parts] => Array
(
[0] => stdClass Object
(
[type] => 0
[encoding] => 0
[ifsubtype] => 1
[subtype] => PLAIN
[ifdescription] => 0
[ifid] => 0
[lines] => 1
[bytes] => 11
[ifdisposition] => 0
[ifdparameters] => 0
[ifparameters] => 1
[parameters] => Array
(
[0] => stdClass Object
(
[attribute] => charset
[value] => UTF-8
)
)
)
[1] => stdClass Object
(
[type] => 0
[encoding] => 0
[ifsubtype] => 1
[subtype] => HTML
[ifdescription] => 0
[ifid] => 0
[lines] => 1
[bytes] => 136
[ifdisposition] => 0
[ifdparameters] => 0
[ifparameters] => 1
[parameters] => Array
(
[0] => stdClass Object
(
[attribute] => charset
[value] => UTF-8
)
)
)
)
)
[1] => stdClass Object
(
[type] => 5
[encoding] => 3
[ifsubtype] => 1
[subtype] => JPEG
[ifdescription] => 0
[ifid] => 1
[id] =>
[bytes] => 25378
[ifdisposition] => 1
**[disposition] => inline**
[ifdparameters] => 1
[dparameters] => Array
(
[0] => stdClass Object
(
[attribute] => filename
[value] => 1.jpg
)
)
[ifparameters] => 1
[parameters] => Array
(
[0] => stdClass Object
(
[attribute] => name
[value] => 1.jpg
)
)
)
)
)
What is the best way to achieve this? And Also How can I understand properly how to move and get any specific element in array?
echo var_export($structure);
stdClass::__set_state(array(
'type' => 1,
'encoding' => 0,
'ifsubtype' => 1,
'subtype' => 'RELATED',
'ifdescription' => 0,
'ifid' => 0,
'ifdisposition' => 0,
'ifdparameters' => 0,
'ifparameters' => 1,
'parameters' =>
array (
0 =>
stdClass::__set_state(array(
'attribute' => 'boundary',
'value' => '047d7b624dd8b40cbc05172d65ae',
)),
),
'parts' =>
array (
0 =>
stdClass::__set_state(array(
'type' => 1,
'encoding' => 0,
'ifsubtype' => 1,
'subtype' => 'ALTERNATIVE',
'ifdescription' => 0,
'ifid' => 0,
'ifdisposition' => 0,
'ifdparameters' => 0,
'ifparameters' => 1,
'parameters' =>
array (
0 =>
stdClass::__set_state(array(
'attribute' => 'boundary',
'value' => '047d7b624dd8b40cb805172d65ad',
)),
),
'parts' =>
array (
0 =>
stdClass::__set_state(array(
'type' => 0,
'encoding' => 0,
'ifsubtype' => 1,
'subtype' => 'PLAIN',
'ifdescription' => 0,
'ifid' => 0,
'lines' => 1,
'bytes' => 11,
'ifdisposition' => 0,
'ifdparameters' => 0,
'ifparameters' => 1,
'parameters' =>
array (
0 =>
stdClass::__set_state(array(
'attribute' => 'charset',
'value' => 'UTF-8',
)),
),
)),
1 =>
stdClass::__set_state(array(
'type' => 0,
'encoding' => 0,
'ifsubtype' => 1,
'subtype' => 'HTML',
'ifdescription' => 0,
'ifid' => 0,
'lines' => 1,
'bytes' => 136,
'ifdisposition' => 0,
'ifdparameters' => 0,
'ifparameters' => 1,
'parameters' =>
array (
0 =>
stdClass::__set_state(array(
'attribute' => 'charset',
'value' => 'UTF-8',
)),
),
)),
),
)),
1 =>
stdClass::__set_state(array(
'type' => 5,
'encoding' => 3,
'ifsubtype' => 1,
'subtype' => 'JPEG',
'ifdescription' => 0,
'ifid' => 1,
'id' => '',
'bytes' => 25378,
'ifdisposition' => 1,
'disposition' => 'inline',
'ifdparameters' => 1,
'dparameters' =>
array (
0 =>
stdClass::__set_state(array(
'attribute' => 'filename',
'value' => '1.jpg',
)),
),
'ifparameters' => 1,
'parameters' =>
array (
0 =>
stdClass::__set_state(array(
'attribute' => 'name',
'value' => '1.jpg',
)),
),
)),
),
))
for($i = 0; $i < count($structure->parts); $i++) {
if($structure->parts[$i]->disposition == inline) {
foreach($structure->parts[$i]->dparameters as $object) {
$src_cid = $object->value;
}
}
}
dispositionyou highlighted is within another that itself could have adisposition. Do you want to recurse through the structure and get all of thedispositionelements, or the first one? If there were multiple attachments, I believe you will have several.[ifdisposition] => 1in the same structure indicates there is adispositionproperty present.echo var_export($that_array);in addition to theprint_r()to make it easier for us to prototype a response?