作者 何书鹏
1 个管道 的构建 通过 耗费 4 秒

高效判断远程图片是否存在

... ... @@ -44,4 +44,32 @@ function createRoundImg($imgpath) {
header("content-type:image/png");
imagepng($image,$imgpath);
imagedestroy($image);
}
/**
* 高效判断远程图片是否存在
*/
function remoteImageExist($url)
{
// $exif_imagetype = [
// 1 => 'GIF',
// 2 => 'JPG',
// 3 => 'PNG',
// 4 => 'SWF',
// 5 => 'PSD',
// 6 => 'BMP',
// 7 => 'TIFF(intel byte order)',
// 8 => 'TIFF(motorola byte order)',
// 9 => 'JPC',
// 10 => 'JP2',
// 11 => 'JPX',
// 12 => 'JB2',
// 13 => 'SWC',
// 14 => 'IFF',
// 15 => 'WBMP',
// 16 => 'XBM'
// ];
$isExsit = @exif_imagetype($url);
if ($isExsit === false) return false;
return in_array($isExsit, [1, 2, 3]) ? true : false;
}
\ No newline at end of file
... ...
... ... @@ -681,7 +681,7 @@ class User extends Api
{
$user = \app\api\model\User::get($this->auth->id);
empty($user['avatar']) && $this->error('请先上传头像');
!remoteImageExist($user['avatar']) && $this->error('头像失效,请更新头像');
// 本地路径
$dir = 'uploads/user';
if (!file_exists($dir)){
... ...