加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php实现从上传文件创建缩略图的方法

发布时间:2020-12-12 20:48:57 所属栏目:PHP教程 来源:网络整理
导读:本篇章节讲解php实现从上传文件创建缩略图的方法。供大家参考研究。具体实现方法如下: 102400){ $error=1; $msg = "The photo is over 100kb. Please try again.";}////////////////////////////////// CHECK TYPE (IE AND OTHERS) //if ($userfile

本篇章节讲解php实现从上传文件创建缩略图的方法。分享给大家供大家参考。具体实现方法如下:

102400){ $error=1; $msg = "The photo is over 100kb. Please try again."; } //////////////////////////////// // CHECK TYPE (IE AND OTHERS) // if ($userfile_type="image/pjpeg"){ if ($userfile_type!="image/jpeg"){ $error=1; $msg = "The photo must be JPG"; } } ////////////////////////////// //CHECK WIDTH/HEIGHT // if ($large_width!=600 or$large_height!=400){ $error=1; $msg = "The photo must be 600x400 pixels"; } /////////////////////////////////////////// //CREATE THUMB / UPLOAD THUMB AND PHOTO /// if ($error<>1){ $image = $userfile_name; //if you want to insert it to the database $pic = imagecreatefromjpeg($userfile); $small = imagecreatetruecolor($small_width,$small_height); imagecopyresampled($small,$pic,$small_width,$small_height,$large_width,$large_height); if (imagejpeg($small,"path/to/folder/to/upload/thumb".$userfile_name,100)){ $large = imagecreatetruecolor($large_width,$large_height); imagecopyresampled($large,$large_height,$large_height); if (imagejpeg($large,"path/to/folder/to/upload/photo".$userfile_name,100)) {} else {$msg="A problem has occured. Please try again."; $error=1;} } else { $msg="A problem has occured. Please try again."; $error=1; } } ////////////////////////////////////////////// /// If everything went right a photo (600x400) and /// a thumb(120x90) were uploaded to the given folders } ?> create thumb

希望本文所述对大家的php程序设计有所帮助。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读