我有以下代码来给自己发送一张图片
$img = file_get_contents("http://www.cpc.ncep.noaa.gov/products/predictions/threats/hazards_d3_7_contours.png");
file_put_contents("hazards_d3_7_contours.png",$img);
$message = $img;
$headers = "From: me";
$headers = "Content-type: image/gif";
$subject = '3-7 Weather Hazard Forecast';
$to = 'me@gmail.com';
mail($to, $subject, $message, $headers);然而,我得到的图像是坏的,你知道为什么吗?
发布于 2013-05-26 09:39:55
图像的文件扩展名为.png,而您却将其作为image/gif发送。也许这跟这件事有关?
发布于 2013-05-26 09:43:57
即使从远程服务器检索到的图像是image/png,发送的电子邮件也是使用mimetype image/gif。然后用from值覆盖标头。你要找的东西是这样的:
$headers = [];
$headers[] = 'From: me';
$headers[] = 'Content-type: image/png';
$subject = '3-7 Weather Hazard Forecast';
$to = 'me@gmail.com';
mail($to, $subject, $message, implode(PHP_EOL, $headers));发布于 2019-03-18 17:51:41
这对我很有效:
public function store()
{
$file = file_get_contents($_FILES['myfile']['tmp_name']);
file_put_contents("img/" . $_FILES['myfile']['name'], $file);
return $_FILES['myfile'];
}https://stackoverflow.com/questions/16755455
复制相似问题