基于laravel,一个下载远程图片到本地, 返回 MD5的方法
<?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; }
相关推荐
-
原生PHP生成 excl、word文件 php
2019-1-8
-
去除字符串的前面的数字 php
2019-1-7
-
根据日期获取当月的开始时间和结束时间 php
2019-1-8
-
PHP图片压缩类,高清无损 php
2019-1-8
-
php自动部署服务器代码 php
2019-1-13
-
php 获取IP与IP所在城市 php
2019-1-7
-
php 获取一张图片所有点的颜色值 php
2019-1-7
-
thinkphp上传图片,生成缩略图 php
2019-1-7
-
8个新鲜的PHP常用代码 php
2019-1-8
-
查询并去除重复二维数组(某个字段筛选) php
2019-1-8