laravel 图片流_基于laravel,一个下载远程图片到本地, 返回 MD5的方法
发布日期:2021-06-24 17:21:52 浏览次数:2 分类:技术文章

本文共 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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:python powershell库_PowerShell封装了Python for .NET实现从PowerShell调用Python
下一篇:双千兆和双频千兆哪个好_双频路由器和单频路由器哪个好【详细介绍】

发表评论

最新留言

感谢大佬
[***.8.128.20]2024年04月04日 11时14分24秒