php上传缩略图

//获得缩略图
function GetDDImage($litpic,$picname,$isremote)
{
    global $cuserLogin,$cfg_ddimg_width,$cfg_ddimg_height,$cfg_basedir,$ddcfg_image_dir,$cfg_addon_savetype;
    $ntime = time();
    if( ($litpic != 'none' || $litpic != 'ddfirst') && 
     !empty($_FILES[$litpic]['tmp_name']) && is_uploaded_file($_FILES[$litpic]['tmp_name']))
    {
        //如果用户自行上传缩略图
        $istype = 0;
        $sparr = Array("image/pjpeg","image/jpeg","image/gif","image/png");
        $_FILES[$litpic]['type'] = strtolower(trim($_FILES[$litpic]['type']));
        if(!in_array($_FILES[$litpic]['type'],$sparr))
        {
            ShowMsg("上传的图片格式错误,请使用JPEG、GIF、PNG格式的其中一种!","-1");
            exit();
        }
        $savepath = $ddcfg_image_dir.'/'.MyDate($cfg_addon_savetype, $ntime);

        CreateDir($savepath);
        $fullUrl = $savepath.'/'.dd2char(MyDate('mdHis',$ntime).$cuserLogin->getUserID().mt_rand(1000,9999));
        if(strtolower($_FILES[$litpic]['type'])=="image/gif")
        {
            $fullUrl = $fullUrl.".gif";
        }
        else if(strtolower($_FILES[$litpic]['type'])=="image/png")
        {
            $fullUrl = $fullUrl.".png";
        }
        else
        {
            $fullUrl = $fullUrl.".jpg";
        }

        @move_uploaded_file($_FILES[$litpic]['tmp_name'],$cfg_basedir.$fullUrl);
        $litpic = $fullUrl;

        if($GLOBALS['cfg_ddimg_full']=='Y') @ImageResizeNew($cfg_basedir.$fullUrl,$cfg_ddimg_width,$cfg_ddimg_height);
        else @ImageResize($cfg_basedir.$fullUrl,$cfg_ddimg_width,$cfg_ddimg_height);

        $img = $cfg_basedir.$litpic;

    }
    else
    {

        $picname = trim($picname);
        if($isremote==1 && eregi("^http://",$picname))
        {
            $litpic = $picname;

            $ddinfos = GetRemoteImage($litpic,$cuserLogin->getUserID());

            if(!is_array($ddinfos))
            {
                $litpic = '';
            }
            else
            {
                $litpic = $ddinfos[0];
                if($ddinfos[1] > $cfg_ddimg_width || $ddinfos[2] > $cfg_ddimg_height)
                {
                    if($GLOBALS['cfg_ddimg_full']=='Y') @ImageResizeNew($cfg_basedir.$litpic,$cfg_ddimg_width,$cfg_ddimg_height);
                    else @ImageResize($cfg_basedir.$litpic,$cfg_ddimg_width,$cfg_ddimg_height);
                }
            }
        }
        else
        {
            if($litpic=='ddfirst' && !eregi("^http://",$picname))
            {
                $oldpic = $cfg_basedir.$picname;
                $litpic = str_replace('.','-lp.',$picname);
                if($GLOBALS['cfg_ddimg_full']=='Y') @ImageResizeNew($oldpic,$cfg_ddimg_width,$cfg_ddimg_height,$cfg_basedir.$litpic);
                else @ImageResize($oldpic,$cfg_ddimg_width,$cfg_ddimg_height,$cfg_basedir.$litpic);
                if(!is_file($cfg_basedir.$litpic)) $litpic = '';
            }
            else
            {
                $litpic = $picname;
                return $litpic;
            }
        }
    }
    if($litpic=='litpic' || $litpic=='ddfirst')
    {
        $litpic = '';
    }
    return $litpic;
}

Leave a Reply

(will not be published)