找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1727|回复: 0
打印 上一主题 下一主题

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

[复制链接]

2487

主题

2487

帖子

7391

积分

论坛元老

Rank: 8Rank: 8

积分
7391
跳转到指定楼层
楼主
发表于 2018-2-14 05:47:18 | 只看该作者 回帖奖励 |正序浏览 |阅读模式

            本文实例讲述了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 ($error1){
  $image = $userfile_name; //if you want to insert it to the database
  $pic = imagecreatefromjpeg($userfile);
  $small = imagecreatetruecolor($small_width,$small_height);
  imagecopyresampled($small,$pic,0,0,0,0, $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,$pic,0,0,0,0, $large_width, $large_height, $large_width, $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

Select Photo:


希望本文所述对大家的php程序设计有所帮助。
            
            
您可能感兴趣的文章:
  • 如何从一个php文件向另一个地址post数据,不用表单和隐藏的变量的
  • PHP实现ftp上传文件示例
  • PHP文件上传判断file是否己选择上传文件的方法
  • php上传文件问题汇总
  • php上传文件常见问题总结
  • php curl 上传文件代码实例
  • php实现通过ftp上传文件
  • PHP整合七牛实现上传文件
  • 求帮忙修改个php curl模拟post请求内容后并下载文件的解决思路
  • PHP判断上传文件类型的解决办法
  • PHP响应post请求上传文件的方法
            
  • 分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    用户反馈
    客户端