Monday 15 February 2010

Isolating picture attachment from email with php -


I am using the following php script and to receive the email later to handle different pieces Put in the variable From stdin $ fd = fopen ("php: // stdin", "r") / p>

  #! / Usr / bin / php -q & lt ;? Read php //; $ Email = ""; While (! FIF ($ FD)) {$ email = Fread ($ fd, 1024); } Fclose ($ fd); // handle email $ line = explosion ("\ n", $ email); // empty wars $ = ""; $ Theme = ""; $ Header = ""; $ Message = ""; $ Partition head = true; ($ I = 0; $ i & lt; Count ($ rows); $ i ++) {if ($ splittingheaders) {// This header is $ header = $ Lines [$ i] "\ N"; // See for special headers (preg_match ("/ ^ subject: (. *) /", $ Lines [$ i], $ matches)) {$ subject = $ matches [1]; } If (preg_match ("/ ^ to: (. *) /", $ Rows [$ i], $ matches) {$ from = $ matches [1]; }} And {// not the title, but the message $ message. = $ Rows [$ i]. "\ N"; } If (trim ($ rows [$ i]) == "") {// blank line, header section $ splittingheaders = false has expired; }}  

Where I start to accept a photo attachment and separate it in a variable, I can process it but I need it.

I will use MimeMailParse () then you can just say

 $ Parser = new MimeMailParser (); $ Parser-> setStream (STDIN); // handle image $ path = '/ tmp /'; $ Filename = ''; $ Attachment = $ parser-> gettip (); Foreign Currency ($ attachments as $ attachments) {if (preg_match ('/ ^ image /', $ attachment-> content_type, $ match)) {$ pathinfo = pathinfo ($ attachment-> file name); $ Filename = $ pathinfo ['filename']; If ($ fp = fopen ($ path. $ Filename, 'w')) {while ($ byte = $ enclosure-> read ()) {fill ($ fp, $ bytes); } Fclose ($ fp); }}} 

No comments:

Post a Comment