无法从http帖子中获取附件

时间:2015-08-22 17:47:20

标签: php codeigniter mailgun

我在Google App Engine上使用codeigniter,我的网络应用程序接收电子邮件并解析并在数据库中存储某些值。我正在使用Mailgun。

我能够收到发件人,主题,正文等所有细节但无法检索附件。

我在下面分享了我的代码。

//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];
}

2 个答案:

答案 0 :(得分:0)

取决于您使用的发布方式:

HTML:

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

然后:

//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.
}

或者

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

然后:

//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.
}

获取数据:

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

示例来自/查看更多详细信息: https://github.com/stvnthomas/CodeIgniter-Multi-Upload

答案 1 :(得分:0)

我最近在Stackoverflow上的另一篇文章中找到了这个问题的答案。发布链接。 @heinst的答案正在发挥作用。

Retrieve Attachment from Mailgun Form Post PHP