小编Ser*_*raw的帖子

使用PHP GD库调整大小并保存图像是HELL

我正在编写一个脚本,它将从用户输入上传文件,将其大小调整为缩略图,并将两个新文件名添加到数据库中.

但是,我不能为我的生活弄清楚如何让PHP检测图像的MIME类型,然后将其提供给标题.这是代码,我已经发表评论,试图让它尽可能清晰:

        $picture = $_FILES['picture']['name'];

        /*original file location*/                  
        $file = 'picture/'.$picture.'';
        /*save thumbnail location*/
        $save = 'thumb/tn-'.$picture.'';
        /*append thumbnail filename with tn-*/
        $thumb = 'tn-'.$picture.'';
        /*get original file size*/
        list($width, $height) = getimagesize($file);
        /*get image MIME type*/
        $size = getimagesize($file);
        $fp = fopen($file, "r");
        if ($size && $fp) 
        {
        header("Content-type:".$size['mime']);
        fpassthru($fp);
        exit;
        } 
        else 
        {
        echo 'Error getting filetype.';
        }
        /*define thumbnail dimensions*/
        $modwidth = 300;
        $modheight = 200;
        /*check to see if original file is not too small*/
        if …
Run Code Online (Sandbox Code Playgroud)

php thumbnails gdlib mime-types

4
推荐指数
1
解决办法
6468
查看次数

标签 统计

gdlib ×1

mime-types ×1

php ×1

thumbnails ×1