我如何检索和保存通过表单邮件和邮件发送给我的附件
下面是一些参数
attachment-1
{:filename=>"crabby.gif", :type=>"image/gif", :name=>"attachment-1", :tempfile=>#<Tempfile:/tmp/RackMultipart20140707-2-slsrkh>, :head=>"Content-Disposition: form-data; name=\"attachment-1\"; filename=\"crabby.gif\"\r\nContent-Type: image/gif\r\nContent-Length: 2785\r\n"}
attachment-2
{:filename=>"attached_файл.txt", :type=>"text/plain", :name=>"attachment-2", :tempfile=>#<Tempfile:/tmp/RackMultipart20140707-2-sudxuf>, :head=>"Content-Disposition: form-data; name=\"attachment-2\"; filename=\"attached_файл.txt\"\r\nContent-Type: text/plain\r\nContent-Length: 32\r\n"}
Content-Type
multipart/mixed; boundary="------------020601070403020003080006"发布于 2015-07-09 02:14:26
所以我知道这晚了一年,但我也遇到了同样的问题,我想出了下载附件的方法。post中的文件存储在环境变量$_FILES中。每个文件的信息如下所示:
Array
(
[attachment-1] => Array
(
[name] => ATextFile.txt
[type] => text/plain
[tmp_name] => /tmp/php8zhmlU
[error] => 0
[size] => 70144
)
)文件的路径存储在tmp_name中,因此在本例中,/tmp/php8zhmlU是文件的完整路径。move_uploaded_file将覆盖任何现有文件!要从POST下载所有附件,我编写了一个函数:
function download_attachments($pathToDownloadDirectory)
{
foreach($_FILES as $file)
{
if($file['error'] == "0")
{
if(!(move_uploaded_file($file['tmp_name'], $pathToDownloadDirectory . $file['name'])))
{
return 0;
}
}
else
{
return 0;
}
}
return 1;
}
download_attachments("/Full/Path/To/Some/Dir/");这篇文章的文档可以是found here.
发布于 2015-12-31 22:44:27
如果json解码的附件列表是$files,您可以这样做
$mgClient = new Mailgun('yourApiKey');
foreach ($files as $file){
file_put_contents($file->name,$mgClient->get($file->url)->http_response_body);
}下载每个附件
https://stackoverflow.com/questions/24605291
复制相似问题