function num_rows($queryid) { $this->rows = mysql_num_rows($queryid); if (empty($queryid)){ $this->halt("Query id 无效:".$queryid); } return $this->rows; }
function fetch_array($queryid) { $this->record = mysql_fetch_array($queryid); if (empty($queryid)){ $this->halt("Query id 无效:".$queryid); } return $this->record; }
function fetch_assoc($queryid) { $this->record = mysql_fetch_assoc($queryid); if (empty($queryid)){ $this->halt("Query id 无效:".$queryid); } return $this->record; } function conn(){ $this->conn = mysql_connect($this->servername, $this->dbusername, $this->dbpassword) or die(mysql_error("数据库链接失败")); return $this->conn; } function selectdb(){ if(!mysql_select_db($this->dbname)){ $this->halt("数据库链接失败"); } } function my_close() { // mysql_close($this->conn); mysql_close(); } function fetch_row($queryid) { $this->record = mysql_fetch_row($queryid); if (empty($queryid)){ $this->halt("queryid 无效:".$queryid); } return $this->record; } function fetch_one_num($query) { $this->result = $this->query($query); $this->record = $this->num_rows($this->result); if (empty($query)){ $this->halt("Query id 无效:".$query); } return $this->record; } function fetch_one_array($query) { $this->result = $this->query($query); $this->record = $this->fetch_array($this->result); if (empty($query)){ $this->halt("Query id 无效:".$query); } return $this->record; } function free_result($query){ if (!mysql_free_result($query)){ $this->halt("fail to mysql_free_result"); } } function insert_id(){ $this->insertid = mysql_insert_id(); if (!$this->insertid){ $this->halt("fail to get mysql_insert_id"); } return $this->insertid; } function halt($msg){ global $technicalemail,$debug; $message = "<html>\n<head>\n"; $message .= "<meta content=\"text/html; charset=gb2312\" http-equiv=\"Content-Type\">\n"; $message .= "<STYLE TYPE=\"text/css\">\n"; $message .= "<!--\n"; $message .= "body,td,p,pre {\n"; $message .= "font-family : Verdana, Arial, Helvetica, sans-serif;font-size : 12px;\n"; $message .= "}\n"; $message .= "</STYLE>\n"; $message .= "</head>\n"; $message .= "<body bgcolor=\"#EEEEEE\" text=\"#000000\" link=\"#006699\" vlink=\"#5493B4\">\n"; $message .= "<font size=10><b>系统调试</b></font><font size=6><b>(by 大白菜芯 )</b></font>\n<hr NOSHADE SIZE=1>\n"; $content = "<p>数据库出错:</p><pre><b>".htmlspecialchars($msg)."</b></pre>\n"; $content .= "<b>Mysql error description</b>: ".$this->geterrdesc()."\n<br>"; $content .= "<b>Mysql error number</b>: ".$this->geterrno()."\n<br>"; $content .= "<b>Date</b>: ".date("Y-m-d @ H:i")."\n<br>"; $content .= "<b>Script</b>: http://".$_SERVER[HTTP_HOST].getenv("REQUEST_URI")."\n<br>"; $content .= "<b>Referer</b>: ".getenv("HTTP_REFERER")."\n<br><br>";
// FileName:GDImage.inc.php
// Summary: 图片处理程序
// Author: tyler.wu(大白菜芯)
// CreateTime: 2005-1-12
// LastModifed:2005-1-12
// copyright (c)2005 [email protected]
//==================================================== class GDImage
{
var $sourcePath; //图片存储路径
var $galleryPath; //图片缩略图存储路径
var $toFile = false; //是否生成文件
var $fontName; //使用的TTF字体名称
var $maxWidth = 500; //图片最大宽度
var $maxHeight = 600; //图片最大高度 //==========================================
// 函数: GDImage($sourcePath ,$galleryPath, $fontPath)
// 功能: constructor
// 参数: $sourcePath 图片源路径(包括最后一个"/")
// 参数: $galleryPath 生成图片的路径
// 参数: $fontPath 字体路径
//==========================================
function GDImage($sourcePath, $galleryPath, $fontPath)
{
global $INFO;
$this->sourcePath = $sourcePath;
$this->galleryPath = $galleryPath;
//$this->fontName = $fontPath . "04B_08__.TTF";
$this->fontName = $fontPath."/".$INFO['gd_font'];} //==========================================
// 函数: makeThumb($sourFile,$width=128,$height=128)
// 功能: 生成缩略图(输出到浏览器)
// 参数: $sourFile 图片源文件
// 参数: $width 生成缩略图的宽度
// 参数: $height 生成缩略图的高度
// 返回: 0 失败 成功时返回生成的图片路径
//==========================================
function makeThumb($sourFile,$width=128,$height=128)
{
$imageInfo = $this->getInfo($sourFile);
$sourFile = $this->sourcePath . $sourFile;
$newName = substr($imageInfo["name"], 0, strrpos($imageInfo["name"], ".")) . "_thumb.jpg";
switch ($imageInfo["type"])
{
case 1: //gif
$img = imagecreatefromgif($sourFile);
break;
case 2: //jpg
$img = $this->LoadJpeg($sourFile);
break;
case 3: //png
$img = imagecreatefrompng($sourFile);
break;
default:
return 0;
break;
}
if (!$img)
return 0; $width = ($width > $imageInfo["width"]) ? $imageInfo["width"] : $width;
$height = ($height > $imageInfo["height"]) ? $imageInfo["height"] : $height;
$srcW = $imageInfo["width"];
$srcH = $imageInfo["height"];
if ($srcW * $width > $srcH * $height)
$height = round($srcH * $width / $srcW);
else
$width = round($srcW * $height / $srcH);
//*
if (function_exists("imagecreatetruecolor")) //GD2.0.1
{
$new = imagecreatetruecolor($width, $height);
ImageCopyResampled($new, $img, 0, 0, 0, 0, $width, $height, $imageInfo["width"], $imageInfo["height"]);
}
else
{
$new = imagecreate($width, $height);
ImageCopyResized($new, $img, 0, 0, 0, 0, $width, $height, $imageInfo["width"], $imageInfo["height"]);
}
//*/
if ($this->toFile)
{
if (file_exists($this->galleryPath . $newName))
unlink($this->galleryPath . $newName);
ImageJPEG($new, $this->galleryPath . $newName);
//return $this->galleryPath . $newName;
return $newName;
}
else
{
ImageJPEG($new);
}
ImageDestroy($new);
ImageDestroy($img); }
//==========================================
// 函数: waterMark($sourFile, $text)
// 功能: 给图片加水印
// 参数: $sourFile 图片文件名
// 参数: $text 文本数组(包含二个字符串)
// 返回: 1 成功 成功时返回生成的图片路径
//==========================================
function waterMark($sourFile, $text)
{
$imageInfo = $this->getInfo($sourFile);
$sourFile = $this->sourcePath . $sourFile;
$newName = substr($imageInfo["name"], 0, strrpos($imageInfo["name"], ".")) . "_.jpg";
switch ($imageInfo["type"])
{
case 1: //gif
$img = imagecreatefromgif($sourFile);
break;
case 2: //jpg
$img = $this->LoadJpeg($sourFile);
break;
case 3: //png
$img = imagecreatefrompng($sourFile);
break;
default:
return 0;
break;
}
if (!$img)
return 0; $width = ($this->maxWidth > $imageInfo["width"]) ? $imageInfo["width"] : $this->maxWidth;
$height = ($this->maxHeight > $imageInfo["height"]) ? $imageInfo["height"] : $this->maxHeight;
$srcW = $imageInfo["width"];
$srcH = $imageInfo["height"];
if ($srcW * $width > $srcH * $height)
$height = round($srcH * $width / $srcW);
else
$width = round($srcW * $height / $srcH);
//*
if (function_exists("imagecreatetruecolor")) //GD2.0.1
{
$new = imagecreatetruecolor($width, $height);
ImageCopyResampled($new, $img, 0, 0, 0, 0, $width, $height, $imageInfo["width"], $imageInfo["height"]);
}
else
{
$new = imagecreate($width, $height);
ImageCopyResized($new, $img, 0, 0, 0, 0, $width, $height, $imageInfo["width"], $imageInfo["height"]);
}
$white = imageColorAllocate($new, 255, 255, 255);
$black = imageColorAllocate($new, 0, 0, 0);
$alpha = imageColorAllocateAlpha($new, 230, 230, 230, 40);
//$rectW = max(strlen($text[0]),strlen($text[1]))*7;
ImageFilledRectangle($new, 0, $height-26, $width, $height, $alpha);
ImageFilledRectangle($new, 13, $height-20, 15, $height-7, $black);
ImageTTFText($new, 4.9, 0, 20, $height-14, $black, $this->fontName, $text[0]);
ImageTTFText($new, 4.9, 0, 20, $height-6, $black, $this->fontName, $text[1]);
//*/
if ($this->toFile)
{
if (file_exists($this->galleryPath . $newName))
unlink($this->galleryPath . $newName);
ImageJPEG($new, $this->galleryPath . $newName);
//return $this->galleryPath . $newName;
return $newName;
}
else
{
ImageJPEG($new);
}
ImageDestroy($new);
ImageDestroy($img); } //==========================================
// 函数: LoadJpeg ($imgname)
// 功能: 显示指定jpg图片的错误处理
// 参数: $imgname 文件名
// 返回: 0 图片不存在
//========================================== function LoadJpeg ($imgname) {
$im = @imagecreatefromjpeg ($imgname); /* Attempt to open */
if (!$im) { /* See if it failed */
$im = imagecreate (150, 30); /* Create a blank image */
$bgc = imagecolorallocate ($im, 255, 255, 255);
$tc = imagecolorallocate ($im, 0, 0, 0);
imagefilledrectangle ($im, 0, 0, 150, 30, $bgc);
/* Output an errmsg */
imagestring ($im, 1, 5, 5, "Error loading $imgname", $tc);
}
return $im;
}//==========================================
// 函数: displayThumb($file)
// 功能: 显示指定图片的缩略图
// 参数: $file 文件名
// 返回: 0 图片不存在
//==========================================
function displayThumb($file,$Old_img)
{
$thumbName = substr($file, 0, strrpos($file, ".")) . "_thumb.jpg";
$file = $this->galleryPath . $thumbName;
if (!file_exists($file)) {
if ($Old_img!="" && file_exists($Old_img)){
$html = "<img src='$Old_img' style='border:1px solid #000' width=128/>";
}else{
$html = "<img src='test.jpg' style='border:1px solid #000' width=128/>";
}
}else{
$html = "<img src='$file' style='border:1px solid #000'/>";
}
return $html;
}
//==========================================
// 函数: displayMark($file)
// 功能: 显示指定图片的水印图
// 参数: $file 文件名
// 返回: 0 图片不存在
//==========================================
function displayMark($file)
{
$Name = substr($file, 0, strrpos($file, ".")) . "_.jpg";
$file = $this->galleryPath . $Name;
if (!file_exists($file)){
$file="test.jpg";
}
$html = "<img src='$file' style='border:1px solid #000'/>";
return $html;
}
//==========================================
// 函数: getInfo($file)
// 功能: 返回图像信息
// 参数: $file 文件路径
// 返回: 图片信息数组
//==========================================
function getInfo($file)
{
$file = $this->sourcePath . $file;
if (file_exists($file)) {
$data = getimagesize($file);
$imageInfo["width"] = $data[0];
$imageInfo["height"]= $data[1];
$imageInfo["type"] = $data[2];
$imageInfo["name"] = basename($file);
}
return $imageInfo;
} } ?>
if(!empty($File_name)){ //判断是否有文件被上传
$File_size=ceil(filesize($File)/2048);
//如果文件大于200K则不能上传。
if ($File_size>200) {
echo "<script language=javascript>alert('文件必须小于200K!');";
echo "javascript:window.history.back(-1);</script>";
exit;
}
$extname=substr($File_name,-3);
$extname=strtolower($extname);
if($extname!="gif" && $extname!="jpg"){ $err .="* 文件格式只能为gif或jpg格式!<br>";
echo "<script language=javascript>alert('文件格式只能是GIF或JPG格式!');";
echo "javascript:window.history.back(-1);</script>";
exit;
//检测上传的文件名的后缀是否是GIF OR JPG如果不是。则返回上一步操作。 } else{
//如果文件上传条件满足。则将此文件COPY到指定路径中。并赋予数据库中的名称 $ntime=time();
$rand =rand(1,31000);
$File_New = $Path."/".$ntime.$rand.".".$extname;
$File_NewName = $ntime.$rand.".".$extname; @copy($File,$File_New); if ($old_File<>"") {
//如果有旧文件就删除掉旧的!
@unlink($Path."/".$old_File);
unlink ($INFO['article_images']."/".$Thumbimg);
unlink ($INFO['article_images']."/".$Markimg);
}
// 开始做GD库的处理
include_once ("GDImage.inc.php");
$Spath = $Path."/";
$GDImg = new GDImage($Spath,$INFO['article_images']."/","../ttf");
$text = array($INFO['gd_text_first'],$INFO['gd_text_second']);
$GDImg->toFile = true;
$ImgMark = $GDImg->waterMark($File_New, $text);
$ImgThumb= $GDImg->makeThumb($File_New);
//$ImgThumb = $GDImg->displayThumb($File_NewName,$Old_img);
//$ImgMark = $GDImg->displayMark($File_New);
$File_NewName = array($File_NewName,$ImgThumb,$ImgMark); //将最后GD成的资料形成一个ARRAY();
} } else { $File_NewName = $old_File; }
//完成新数据的插入工作。 return $File_NewName; }
$DB 是一个数据库封装的类,
$INFO 是一个全局的数组
return $File_NewName;也是一个数组。外部处理的时候要注意一下!!
下边我在把我用到的这个$DB给你。应该100%可以调试成功了!
<?php
//屏蔽未定义错误
//error_reporting(7);class DB_MySQL { var $servername="localhost";
var $dbname="online2";
var $dbusername = "root";
var $dbpassword = "root";
var $conn = 0;
var $technicalemail='[email protected]';
function geterrdesc() {
$this->error = @mysql_error($this->conn);
return $this->error;
} function geterrno() {
$this->errno = @mysql_errno($this->conn);
return $this->errno;
}
function query($query_string) {
// $this->result = mysql_db_query($this->dbname,$query_string);
$this->result = mysql_query($query_string);
if (!$this->result) {
$this->halt("SQL 无效: ".$query_string);
}
return $this->result;
}
function num_rows($queryid) { $this->rows = mysql_num_rows($queryid); if (empty($queryid)){
$this->halt("Query id 无效:".$queryid);
}
return $this->rows;
}
function fetch_array($queryid) { $this->record = mysql_fetch_array($queryid);
if (empty($queryid)){
$this->halt("Query id 无效:".$queryid);
}
return $this->record;
}
function fetch_assoc($queryid) { $this->record = mysql_fetch_assoc($queryid);
if (empty($queryid)){
$this->halt("Query id 无效:".$queryid);
}
return $this->record;
} function conn(){
$this->conn = mysql_connect($this->servername, $this->dbusername, $this->dbpassword) or die(mysql_error("数据库链接失败"));
return $this->conn;
} function selectdb(){
if(!mysql_select_db($this->dbname)){
$this->halt("数据库链接失败");
}
}
function my_close() {
// mysql_close($this->conn);
mysql_close();
} function fetch_row($queryid) { $this->record = mysql_fetch_row($queryid);
if (empty($queryid)){
$this->halt("queryid 无效:".$queryid);
}
return $this->record;
} function fetch_one_num($query) { $this->result = $this->query($query);
$this->record = $this->num_rows($this->result);
if (empty($query)){
$this->halt("Query id 无效:".$query);
}
return $this->record; }
function fetch_one_array($query) { $this->result = $this->query($query);
$this->record = $this->fetch_array($this->result);
if (empty($query)){
$this->halt("Query id 无效:".$query);
}
return $this->record; }
function free_result($query){
if (!mysql_free_result($query)){
$this->halt("fail to mysql_free_result");
}
} function insert_id(){
$this->insertid = mysql_insert_id();
if (!$this->insertid){
$this->halt("fail to get mysql_insert_id");
}
return $this->insertid;
}
function halt($msg){ global $technicalemail,$debug; $message = "<html>\n<head>\n";
$message .= "<meta content=\"text/html; charset=gb2312\" http-equiv=\"Content-Type\">\n";
$message .= "<STYLE TYPE=\"text/css\">\n";
$message .= "<!--\n";
$message .= "body,td,p,pre {\n";
$message .= "font-family : Verdana, Arial, Helvetica, sans-serif;font-size : 12px;\n";
$message .= "}\n";
$message .= "</STYLE>\n";
$message .= "</head>\n";
$message .= "<body bgcolor=\"#EEEEEE\" text=\"#000000\" link=\"#006699\" vlink=\"#5493B4\">\n";
$message .= "<font size=10><b>系统调试</b></font><font size=6><b>(by 大白菜芯 )</b></font>\n<hr NOSHADE SIZE=1>\n";
$content = "<p>数据库出错:</p><pre><b>".htmlspecialchars($msg)."</b></pre>\n";
$content .= "<b>Mysql error description</b>: ".$this->geterrdesc()."\n<br>";
$content .= "<b>Mysql error number</b>: ".$this->geterrno()."\n<br>";
$content .= "<b>Date</b>: ".date("Y-m-d @ H:i")."\n<br>";
$content .= "<b>Script</b>: http://".$_SERVER[HTTP_HOST].getenv("REQUEST_URI")."\n<br>";
$content .= "<b>Referer</b>: ".getenv("HTTP_REFERER")."\n<br><br>";
$message .= $content;
$message .= "<p>请尝试刷新你的浏览器,如果仍然无法正常显示,请联系<a href=\"mailto:".$this->technicalemail."\">管理员</a>.</p>";
$message .= "</body>\n</html>";
echo $message; $headers = "From: nt.cn <$this->technicalemail>\r\n"; $content = strip_tags($content);
//@mail($technicalemail,"数据库出错",$content,$headers); exit;
}
}
?>