zoukankan      html  css  js  c++  java
  • 新浪云-PHP实现上传原图,缩略图

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <html> 
    <head> 
    <title>新浪云图片上传程序</title> 
    </head> 
    <form enctype="multipart/form-data" method="post" name="upform"> 
    <input name="upfile" type="file"> 
    <input type="submit" value="上传">
    </form> 
    <?php 
    function test_input($data)
    {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
    }
    function create_guid() {
    $charid = strtoupper(md5(uniqid(mt_rand(), true)));
    $uuid = 
    substr($charid, 0, 8)
    .substr($charid, 8, 4)
    .substr($charid,12, 4)
    .substr($charid,16, 4);
    return $uuid;
    }
    function UploadSmallImage($src,$w,$smallscr)
    {
    $temp=pathinfo($src);
    $name=$smallscr;//文件名
    $dir=$temp["dirname"];//文件所在的文件夹
    $extension=$temp["extension"];//文件扩展名
    $savepath="image_small/{$name}";//缩略图保存路径,新的文件名为*.thumb.jpg
    $info=getimagesize($src);
    $width=$info[0];//获取图片宽度
    $height=$info[1];//获取图片高度
    $type=$info[2];
    switch($type){
    case 1:$im=imagecreatefromgif($src);break;
    case 2:$im=imagecreatefromjpeg($src);break;
    case 3:$im=imagecreatefrompng($src);break;
    default:break;
    }
    if ($w == 385) {
    $h = 500;
    } elseif ($w == 225) {
    $h = 300;
    } elseif ($w == 75) {
    $h = 100;
    }
    $temp_img=imagecreatetruecolor($w,$h);//创建画布
    imagecopyresized($temp_img,$im,0,0,0,0,$w,$h,$width,$height);
    $s = new SaeStorage();
    ob_start();
    imagejpeg($temp_img);
    $imgstr = ob_get_contents();
    $s->write('w376161501',$savepath,$imgstr);
    ob_end_clean();
    imagedestroy($im);
    return $savepath; 
    }
    function UploadBigImage($src,$smallscr)
    {
    $temp=pathinfo($src);
    $name=$smallscr;//文件名
    $dir=$temp["dirname"];//文件所在的文件夹
    $extension=$temp["extension"];//文件扩展名
    $savepath="image_big/{$name}";//缩略图保存路径,新的文件名为*.thumb.jpg
    $info=getimagesize($src);
    $width=$info[0];//获取图片宽度
    $height=$info[1];//获取图片高度
    $type=$info[2];
    switch($type){
    case 1:$im=imagecreatefromgif($src);break;
    case 2:$im=imagecreatefromjpeg($src);break;
    case 3:$im=imagecreatefrompng($src);break;
    default:break;
    }
    $s = new SaeStorage();
    ob_start();
    imagejpeg($im);
    $imgstr = ob_get_contents();
    $s->write('w376161501',$savepath,$imgstr);
    ob_end_clean();
    return $savepath; 
    }
    if ($_SERVER['REQUEST_METHOD'] == 'POST') 
    { 
    $file = $_FILES["upfile"]; 
    $filename=$file["tmp_name"]; 
    $image_size = getimagesize($filename); 
    $pinfo=pathinfo($file["name"]); 
    $ftype=$pinfo['extension']; 
    $imagesmall=create_guid().".".$ftype;
    $big=UploadBigImage($_FILES['upfile']['tmp_name'],$imagesmall);
    $small=UploadSmallImage($_FILES['upfile']['tmp_name'],225,$imagesmall);
    echo '原图:'.$small.'缩略图:'.$big;
    }
    
    ?> 
    </body> 
    </html>
  • 相关阅读:
    在ThinkPHP中生成中文验证码
    Touch event in certain color rect
    安装GD后不支持PNG或JPG的修复办法
    iPhone开发:proximityMonitoring邻近检测
    开放CSDN博客-欢迎到访-另附声明
    (实例篇)LNMP 1.4一键安装包,安装教程
    流量相关说明
    一个空间主机安装多个网站的方法
    怎么使用linux命令重启服务器
    CentOS、Ubuntu、Debian三个linux比较异同
  • 原文地址:https://www.cnblogs.com/wangboke/p/5603081.html
Copyright © 2011-2022 走看看