【问题标题】:Unable to fetch attachments from http post无法从 http post 获取附件
【发布时间】:2015-08-22 17:47:19
【问题描述】:

我在 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];
}

【问题讨论】:

    标签: php codeigniter mailgun


    【解决方案1】:

    取决于您使用哪种发帖方式:

    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

    【讨论】:

    • 我正在使用 mailgun,电子邮件作为 http 帖子转发到 example.com/email。我从这里获取详细信息。当我使用谷歌应用引擎时,我无法将附件上传到文件系统。我需要将它们保存到数据库中。
    • 那么文件将作为 POST 数据中的数组发送?如果是这样,请看这里: list($day) = $this->input->post("days"); stackoverflow.com/questions/3112690/…
    【解决方案2】:

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

    Retrieve Attachment from Mailgun Form Post PHP

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-04
      • 1970-01-01
      • 1970-01-01
      • 2021-03-09
      • 2011-03-13
      • 1970-01-01
      • 1970-01-01
      • 2016-11-25
      相关资源
      最近更新 更多