function thu2mb($aid, $width = 320, $height = 200, $bg = true, $pnum = 0) { global $dsql,$cfg_mainsite,$cfg_multi_site; $imgarr = array(); //获取文档模型 $aid = trim(ereg_replace('[^0-9]','',$aid)); $cy = $dsql->GetOne("Select type.channeltype From `#@__arctype` type, `#@__archives` main where main.id='$aid' and main.typeid=type.id"); $ctype = $cy['channeltype']; if($ctype == 1){//文章模型 $imgquery = $dsql->GetOne("Select arc.body,arc.typeid From `#@__addonarticle` arc where arc.aid='$aid'"); preg_match_all("/<img[\s\S]*?src=[\"']([\s\S]*?)[\"']/", $imgquery['body'], $imgarr); $pnum = $imgquery['typeid']==6 ? count($imgarr[1])-1 : 0; }else if($ctype == 2){ $imgquery = $dsql->GetOne("Select art.imgurls From `#@__addonimages` art where art.aid='$aid'"); preg_match_all("/dede:img ddimg='(.*?)' text='/",$imgquery['imgurls'],$imgarr); }else{ return"文章模型错误"; } $imgurl = $imgarr[1][$pnum]; if(!$imgurl) return; $thumb = eregi("http://",$imgurl)?str_replace($cfg_mainsite,'',$imgurl):$imgurl; if(preg_match('http://',$thumb)){ echo '调用随机文档中包含未下载图片请编辑以下文档<br><a href="http://www.qmtx3.com/后台目录">点击修改</a>'; exit; }; $from = $thumb; $newthumb = preg_replace("/(.*\/)/", "$1'$width"."_".$height."_", $thumb); $newthumb = preg_replace("/\'/", "", $newthumb); $thumb = str_replace('uploads','uploads/lit',$newthumb); $thumb = str_replace('allimg/','',$thumb); if(!file_exists(DEDEROOT.$thumb)) { $imgdir = preg_match('/.*\//',$thumb,$imgdirarr); $imgdir = DEDEROOT.$imgdirarr[0]; tmkdirs($imgdir); if(!is_dir($imgdir)) { echo $aid."<br>"; echo '<a href="http://www.qmtx3.com/后台目录">修改该文章</a>'; echo "ERROR: Create {$imgdir} dir Error! "; exit(0); } list($thumbname,$extname) = explode('.',$thumb); $newthumb = $thumbname.'_'.$width.'_'.$height.'.'.$extname; include_once DEDEINC.'/myThumb/phpthumb.class.php'; $phpThumb = new phpthumb(); $thumbnail_width = $width; if (is_uploaded_file(@$_FILES['userfile']['tmp_name'])) { $phpThumb->setSourceFilename($_FILES['userfile']['tmp_name']); $output_filename = './thumbnails/'.basename($_FILES['userfile']['name']).'_'.$thumbnail_width.'.'.$phpThumb->config_output_format; } else { $phpThumb->setSourceData(file_get_contents(DEDEROOT.$from)); $output_filename = DEDEROOT.$thumb; } $phpThumb->setParameter('config_document_root', DEDEROOT); $phpThumb->setParameter('w', $width); $phpThumb->setParameter('h', $height); $phpThumb->setParameter('far', "'".$width.",".$height."'"); $phpThumb->setParameter('zc', 'C'); //画布背景 $phpThumb->setParameter('bg', 'ffffff'); if ($phpThumb->GenerateThumbnail()) { if ($phpThumb->RenderToFile($output_filename)) { } else { echo 'Failed:<pre>'.implode("\n\n", $phpThumb->debugmessages).'</pre>'; } $phpThumb->purgeTempFiles(); } else { echo 'Failed:<pre>'.$phpThumb->fatalerror."\n\n".implode("\n\n", $phpThumb->debugmessages).'</pre>'; } $output_filename = str_replace(DEDEROOT, "", $output_filename); $query = "UPDATE #@__archives SET litpic='$output_filename',flag='p' WHERE id='$aid'; "; if(!$dsql->ExecuteNoneQuery($query)) { ShowMsg('更新文档缩略图出错,请检查',-1); exit(); } return $output_filename; } else { return $thumb; } } function typeurl_arc($typeid){ $typeurl = ""; global $dsql; $row = $dsql ->GetOne("select typedir from dede_arctype where id=$typeid"); $typeurl = MfTypedir($row['typedir']); return $typeurl; } function tmkdirs($dir) { if(!is_dir($dir)) { if(!tmkdirs(dirname($dir))){ return false; } if(!mkdir($dir,0777)){ return false; } } return true; }