2

I'm using codeigniter on Google App Engine and my web app receives emails and parses and stores certain values in the database. I'm using Mailgun for the same.

I'm able to receive all details like sender, subject, body but not able to retrieve the attachments.

I have shared my code below.

//Everything fine here
$email_subject  = addslashes($this->input->post('subject', ''));
$email_body     = addslashes($this->input->post('body-html', ''));

//Not able to retrieve attachments
for ($i=0; $i <= count($this->input->post('FILES')); $i++) { 
   $email_attach = $this->input->post('FILES')[$i];
}
joe_young
  • 4,107
  • 2
  • 27
  • 38
krish_cloudnow
  • 180
  • 1
  • 13

2 Answers2

0

Depends which method of posting you are using:

Html:

<input type="file" name="files[]" />
<input type="file" name="files[]" />
<input type="file" name="files[]" />

Then:

//Configure upload.
$this->upload->initialize(array(
   "upload_path"   => "/path/to/upload/to/"
));

//Perform upload.
if($this->upload->do_multi_upload("files")) {
    //Code to run upon successful upload.
}

Or

<form>
  <input type="file" name="files[]" multiple />
  <input type="submit" name="submit" value="submit" />
</form>

Then:

//Configure upload.
$this->upload->initialize(array(
   "upload_path"   => "/path/to/upload/to/"
));

//Perform upload.
if($this->upload->do_multi_upload("files")) {
  //Code to run upon successful upload.
}

Getting data:

//Perform upload.
if($this->upload->do_multi_upload("files")) {
   //Print data for all uploaded files.
   print_r($this->upload->get_multi_upload_data());
}

Examples are from / see for more details: https://github.com/stvnthomas/CodeIgniter-Multi-Upload

Redoneben
  • 126
  • 6
  • I'm using mailgun and the email is forwarded as an http post to http://example.com/email. I fetch the details from here. I cannot upload attachment to filesystem as I use google app engine. I need to save them to the DB. – krish_cloudnow Aug 23 '15 at 04:13
  • So the files will be send as an array in POST data? If so, take a look here: list($day) = $this->input->post("days"); http://stackoverflow.com/questions/3112690/getting-data-from-post-array-in-codeigniter – Redoneben Aug 23 '15 at 07:17
0

I have found the answer for this issue recently on a different post on Stackoverflow. Posting the link. The answer from @heinst is working.

Retrieve Attachment from Mailgun Form Post PHP

Community
  • 1
  • 1
krish_cloudnow
  • 180
  • 1
  • 13