[英]How do I save an inline image in an email using piping with PHP?
內嵌圖片在電子郵件的來源中顯示為
--------------090909040108020409080705
Content-Type: image/png;
name="fideghfb.png"
Content-Transfer-Encoding: base64
Content-ID: <part1.05000606.01050306@server.com>
Content-Disposition: inline;
filename="fideghfb.png"
BASE64
--------------090909040108020409080705--
只需從中獲取基數64,您就可以使用Content-Disposition: inline;
尋找一個塊Content-Disposition: inline;
然后base64解碼圖像
這是完全根據答案得出的答案:
//create the array of base64 strings
$pieces = explode("Content-Transfer-Encoding: base64", $email);
array_shift($pieces);
foreach ($pieces as &$value) {
$newString = strstr($value, "\n\n");
$newString = substr($newString, 0, strpos($newString, '--'));
$PicturesData[] = $newString;
}
//save each image
foreach ($PicturesData as &$value) {
$name = time() . ".png";
while(file_exists("pics/" . $name)) {
$name = time() . ".png";
}
file_put_contents("directory/".$name, base64_decode($value));
}
這將創建嵌入在電子郵件中的圖像數組,並將每個圖像另存為不同的名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.