hello everyone,
I'm a noob to php and have been developing a project over the past few weeks and could use some assistance. Basically, I'm building an open community photo blogging system that allows anyone to send an image to an email addy and post a photo to an group of images. So far, everything works, when a user sends an email with an attachment to the address, my php parses the message and pulls the it into a directory, while creating a thumbnail. When someone visits the page, a list of directories is parsed for files, which are sorted into an image array and rendered on the page. So all is well.
Here is where I am stuck. I'd like to extract the subject from each new message and attach it to the associated image. So far, each image name is an array value that is indexed during render-time. I am not sure how to approach this situation. I was thinking that I could setup a mysql table called image with values name and subject, and then parse this table for both during render. I also thought that maybe I could just setup an associated array that mirrors the image array that contains subjects, but my concern is sorting and keeping the values tied to one another.
Here is my code
//
// Open the mailbox
$mbox = imap_open($server, $user, $pass)
or die("I'm sorry, a connection with the server could not be established because of : " . imap_last_error());
// Check for new messages, and if avail, parse for images
$newMsgs = imap_status($mbox, $inbox, SA_UNSEEN);
if($newMsgs->unseen > 0){
$noImages = "<div class='newImgs'>A new image has been added to the list.</div>";
$headerStr = imap_headers($mbox);
foreach ($headerStr as $headerStr){
$multipart = False;
$imgCount = 1; //this number should be a variable, of what?
preg_match("/[0-9]/", $headerStr, $number);
// Parse the message and the sender
// Get the date and output a str
$header = imap_fetchheader($mbox, $number[0]);
preg_match("/Date: (.*)?[\+|-]/", $header, $date);
$date = htmlentities($date[1]);
$date = strtotime($date);
$date = date("y-m-d-h:i:s", $date);
// Get the senders email address
$headerinfo = imap_headerinfo($mbox, $number[0], 256, 256);
$sender_email = " (".$headerinfo->from[0]->mailbox . "@" . $headerinfo->from[0]->host.")";
$decode = imap_mime_header_decode($headerinfo->from[0]->personal);
$sender = $decode[0]->text;
$sender .= $sender_email;
$decode = imap_mime_header_decode($headerinfo->fetchsubject);
$subject = $decode[0]->text;
// Get the image
$imap = imap_fetchstructure($mbox, $number[0]);
if (! empty($imap->parts)){
for($i = 0, $j = count($imap->parts); $i < $j; $i++){
$msg = imap_fetchbody($mbox, $number[0], $i + 1);
$part = $imap->parts[$i];
if ($part->disposition == ATTACHMENT || $part->type == TYPEIMAGE || ($part->type == TYPEAPPLICATION && $part->subtype <> "SMIL")){
if ($part->subtype == "JPEG" || $part->subtype == "jpg" || $part->subtype == "jpeg" || $part->subtype == "JPG"){
if (! $handle = @fopen($pictDir . "$date.$part->subtype", "w")){
die("no permission to write image to $pict_Dir");}
fwrite($handle, imap_base64($msg));
fclose($handle);
$imgName = "$date.$part->subtype";
// Call the makeThumbs.php and create a thumbnail
createThumbnail($pictDir, $imgName, $thumbDir);
// pause for processing
for($i = 0; $i < 50; ++$i);
}
}
}
}
//imap_delete($mbox, $number[0]);
}
}
//imap_expunge($mbox);
imap_close($mbox);
return $imgName;
}
?>
So, can someone help me out with this?
Thanks a mil