栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

常见问题02:php实现图片上传功能(带缩略图)

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

常见问题02:php实现图片上传功能(带缩略图)

源码地址:php实现图片上传功能(带缩略图)

PicUploadSummary

图片上传(带缩略图)

该插件集成了图片上以及图片压缩的功能。

核心方法为:

upload($folder, $thumb = true);
第一个参数$folder为上传的文件到哪个目录的意思,第二个参数默认为true表示同时上传缩略图。

Usage

上传图片:

function uploadPics($filename,$img_dir='test') {        //上传图片部分
        $result = [];        if(!empty($_FILES[$filename]['name'])) {
            $img = new UploadImg($filename);
            $img->upload($img_dir,false);
            $result['pic'] = str_replace(DS, '/', $img->path . '/' . $img->filename);
            $result['width'] = $img->width;
            $result['height'] = $img->height;
            $result['size'] = $img->size;            unset($img);
        }        return $result;
    }

上传图片(带缩略图):

function uploadPics($filename,$img_dir='test') {        //上传图片部分
        $result = [];        if(!empty($_FILES[$filename]['name'])) {

            $img = new UploadImg($filename);
            $thumb_w = 160;//缩略图宽
            $thumb_h = 100;//缩略图高
            $img->add_thumb('thumb', 'thumb_', $thumb_w, $thumb_h);
            $img->use_mment = false; // 关闭最大尺寸限制
            $img->upload($img_dir);

            $result['pic'] = str_replace(DS, '/', $img->path . '/' . $img->filename);
            $result['thumb'] = str_replace(DS, '/', $img->path . '/' . $img->thumb_filenames['thumb']['filename']);
            $result['width'] = $img->width;
            $result['height'] = $img->height;
            $result['size'] = $img->size;            unset($img);
        }        return $result;
    }
Author

nosee123

License

MIT Public License



作者:Nosee123
链接:https://www.jianshu.com/p/8e0f4c14c9b8

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/228376.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号