링크에서 파일을 다운로드했으며 로컬 시스템 폴더 또는 원격 서버 폴더에 저장해야합니다. 시나리오는 다음과 같습니다. mailgun 도메인이 있고 메일을 보낼 때 Mailgun 저장소 기능 ( store()
)이 모든 첨부 파일과 함께 저장하고 알림을 보냅니다. mailgun의 응답은에서 잡히고 응답을 catch_email_attachment()
가져올 수 있으며 첨부 파일의 링크를 얻었습니다. 브라우저에서 직접 링크를 실행하면 첨부 파일이 제공되며 문제는 없습니다. 하지만 파일을 다운로드하여 catch_email_attachment()
폴더에 저장해야합니다.
다운로드 가능한 파일은 " https://API:<API-KEY>@api.mailgun.net/v2/domains/sandboxa6e6ebce3f68475aa3xxxxxxxd60.mailgun.org/messages/eyJwIjogZmFsc2UsICJrIjogImQ0MmZjxxxxxxxxxxxxxxDQwNy1iYzhlLTA2OWMxY2U3MDg2NCIsIxxxxxxxxxxxxxx1Y2UiLCAiYyI6ICJpYWR0cmFpbGVycyJ9/attachments/0
"입니다.
내 코드는 다음과 같습니다.
public function catch_email_attachment()
{
$data = $this->input->post(null, true);
if (!empty($data)) {
if (isset($data['attachments'])) {
/*
Output of $data['attachments'] is below:
[{"url": "https://api.mailgun.net/v2/domains/sandboxa6e6ebce3f68475aa3xxxxxxxd60.mailgun.org/messages/eyJwIjogZmFsc2UsICJrIjogImQ0MmZjxxxxxxxxxxxxxxDQwNy1iYzhlLTA2OWMxY2U3MDg2NCIsIxxxxxxxxxxxxxx1Y2UiLCAiYyI6ICJpYWR0cmFpbGVycyJ9/attachments/0", "content-type": "image/jpeg", "name": "xxxxxxx.jpeg", "size": 9498}]
*/
copy('https://API:[email protected]/v2/domains/sandboxa6e6ebce3f68475axxxxxxxxxxxxxxxxxxxxxxxxxxxx.mailgun.org/messages/eyJwIjogZmFsc2UxxxxxxxxxxxxxxxxxxxxxxxxxxxxmUtNDQwNy1iYzhlLTA2OWMxY2U3MDg2NCIxxxxxxxxxxxxxxxxxxxxxxxxxxxx1Y2UiLCAiYyI6ICJpYWR0cmFpbGVycyJ9/attachments/0', '/var/www/download_loc/');
}
}
}
나는 참조했다 : https://stackoverflow.com/a/26330976/4229270
https://stackoverflow.com/a/6594030/4229270
https://stackoverflow.com/a/724449/4229270
문제 해결을 도와 주시겠습니까? 미리 감사드립니다.
$data['attachments']
json 배열 처럼 보이 므로 다음과 같은 것이 필요합니다.
$attachments = json_decode($data['attachments']);
$api_key = 'APIKEY';
if ($attachments) {
foreach ($attachments as $attachment) {
$context = stream_context_create(array(
'http' => array(
'header' => "Authorization: Basic " . base64_encode("API:$api_key")
)
));
file_put_contents('/var/www/download_loc/' . $attachment->name, file_get_contents($attachment->url, false, $context));
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다