sascha_kote
Threadersteller
Dabei seit: 18.10.2007
Ort: Münster
Alter: -
Geschlecht:
|
Verfasst Mo 03.05.2010 08:50
Titel PHP Problem - Fatal error: Cannot use object of type stdClas |
|
|
hallo,
ich habe plötzlich eine fehlermeldung bei einem php-script, wobei ich mir eigentlich sicher bin, dass ich nichts geändert hatte.
im grunde geht es so:
man schickt ein foto per mail an eine mailadresse.
das script wird aufgerufen, das postfach abgerufen und das foto mit forllaufender nummer in ein verzeichnis gespeichert.
jetzt kommt plötzlich diese fehlermeldung und ich weiß überhaupt nicht woran das liegen könnte
ich hoffe hier hilfe zu finden.
danke
sascha
fehlermeldung:
Fatal error: Cannot use object of type stdClass as array in /verzeichnis/photo.php on line 68
der fehler soll in dieser zeile sein:
$attachment[] = array("filename" => $parts[$i]->parameters[0]->value,
hier das ganze script:
Code: |
<?
/* Konfiguration */
$conf = array();
$conf['host'] = '{imap.domain.de}'; //Accountzugang welches Postfach abgerufen werden soll
$conf['username'] = 'photo@domain.de'; // Zugangsdaten
$conf['password'] = 'test'; //Passwort
$conf['path'] = './bildverzeichnis'; //Bilder werden in dieses Verzeichnis kopiert
$conf['ext'] = array(".gif",".jpg",".jpeg"); //erlaubte Dateiendungen
/* AB HIER NICHTS MEHR EDITIEREN */
$mbox = imap_open ($conf['host'],$conf['username'],$conf['password']);
$headers = imap_headers ($mbox);
if ($headers == false) {
echo "Nothing to do!
\n";
}else{
while (list ($key, $val) = each ($headers)) {
$mid = $key + 1;
$header = imap_header($mbox, $key+1);
$struct = imap_fetchstructure($mbox, $key+1);
extract_attachments($mbox,$mid);
imap_delete($mbox,$mid);
}
imap_expunge($mbox);
imap_close ($mbox);
}
function extract_attachments($mbox,$mid)
{
global $conf;
$struct = imap_fetchstructure($mbox, $mid);
$parts = $struct->parts;
$i = 0;
if (!$parts)
{
$attachment = array();
$content = imap_body($mbox, $mid);
}
else
{
$endwhile = false;
$stack = array();
$content = "";
$attachment = array();
while (!$endwhile)
{
if (!$parts[$i])
{
if (count($stack) > 0)
{
$parts = $stack[count($stack)-1]["p"];
$i = $stack[count($stack)-1]["i"] + 1;
array_pop($stack);
}
else
{
$endwhile = true;
}
}
if (!$endwhile)
{
$partstring = "";
foreach ($stack as $s)
{
$partstring .= ($s["i"]+1) . ".";
}
$partstring .= ($i+1);
if (strtoupper($parts[$i]->disposition) == "ATTACHMENT")
{ /* Attachment */
$attachment[] = array("filename" => $parts[$i]->parameters[0]->value,
"filedata" => imap_fetchbody($mbox, $mid, $partstring));
$encoding = $parts[$i]->encoding;
$ext = strrchr($parts[$i]->parameters[0]->value,'.');
if (in_array($ext, $conf['ext']))
{
$ext == '.jpeg' ? $basename = substr($parts[$i]->parameters[0]->value, 0, -5) : $basename = substr($parts[$i]->parameters[0]->value, 0, -4);
#files sollen immer den gleich namen mit forlaufender Nr. haben
$basename = 'foto'; // Hier steht der Mittelteil des Dateinamens
echo "Bild gefunden: ".$parts[$i]->parameters[0]->value."
";
if(file_exists($conf['path'] . $basename . $ext))
{
$i = 1;
if(file_exists($conf['path'] . $basename . $ext))
{
while(file_exists($conf['path'] . $basename . sprintf("%05s", $i) . $ext))
{
$i++;
}
}
$fp = fopen($conf['path'] . $basename . sprintf("%05s", $i) . $ext,"w+");
}
else
{
$fp = fopen($conf['path'] . $basename . $ext,"w+");
}
if ($encoding == 3)
{
fwrite($fp, base64_decode(imap_fetchbody($mbox, $mid, $partstring)));
}
else
{
fwrite($fp, imap_fetchbody($mbox, $mid, $partstring));
}
}
}
}
if ($parts[$i]->parts) {
$stack[] = array("p" => $parts, "i" => $i);
$parts = $parts[$i]->parts;
$i = 0;
} else {
$i++;
}
}
}
}
?>
|
|
|