本文共 716 字,大约阅读时间需要 2 分钟。
RemoteImage.php
/**
* 下载远程图片到本地, 返回 MD5
*
* @param $url
*
* @return string
*/
public function downloadRemoteImage($url)
{
$url = (string)$url;
$file = request_url($url);
if (!$file) return '';
$fileInfo = getimagesizefromstring($file);
if (!$fileInfo) return '';
$fileType = explode('/', $fileInfo['mime']);
if (empty($fileType) || $fileType['0'] != 'image' || !in_array($fileType[1], $this->imageAllowType)) {
return '';
}
// 大小判断
if (strlen($file) > $this->imageAllowSize) {
return '';
}
// 是否已经上传过
$md5 = md5($file);
$path = $this->md52url($md5, 'image', true);
if (!is_file($path) || getimagesize($path) == false) {
File::makeDirectory(dirname($path), 0777, true, true);
File::put($path, $file);
}
return $md5;
}
转载地址:https://blog.csdn.net/weixin_34081553/article/details/112821824 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!