- 論壇徽章:
- 0
|
inc文件夾:
header.inc
banner.inc
";
break;
case "1";
echo "";
break;
case "2";
echo "";
break;
case "3";
echo "";
break;
case "4";
echo "";
break;
}
?>
navbar.inc
| \n";
while($entry = $d->read())
{
// 忽略無文件情況
if ( !is_file($entry) )
continue;
/* 將文件名與擴展名分開。由于.是正則表達(dá)式特殊字符,應(yīng)該用\引出 */
list($filenm, $fileext) = split("\.",$entry, 2);
// 忽略非.php文件情況
if( $fileext != "php" )
continue;
/* 現(xiàn)在我們已經(jīng)把.php文件都選出,下面搜尋文件中的第一行(標(biāo)題)
類似$title="something";
并將以上標(biāo)題內(nèi)容分開,用作鏈接文字 */
$linknm = "";
$fp=fopen($entry,"r");
while($buffer=fgets($fp, 4096))
{
$buffer = trim($buffer);
// 我們已經(jīng)把每個文件的標(biāo)題放在文件的第一行以便搜索
// 但是當(dāng)你改變變量名稱時可能會帶來大麻煩
if (ereg("title *= *\"", $buffer))
{
/* 我們已經(jīng)取得了標(biāo)題內(nèi)容并可以在此基礎(chǔ)上
進行去除空格等處理。
必須以PHP代碼方式處理,比如$title = "blah blah" */
eval($buffer);
// 然后將鏈接文字顯示為標(biāo)題文字
$linknm = $title;
break;
}
}
fclose($fp);
if ( $entry == basename($PHP_SELF) )
echo "$linknm";
else
echo "$linknm";
echo " | ";
}
$d->close();
echo " \n";
?>
footer.inc
Copyright? by
[email=manxian@56.com ,2007
文本網(wǎng)絡(luò)投票程序
投票頁面:
你最喜歡的美劇?
CSI.S7
Mr.Doctor
House Doctor
24hours
顯示頁面:
rewind($fp);
//倒回文件指針的位置,文件指針必須合法并且指向由fopen()成功打開的文件
$string="";
for($i=0;$i
$vote=vote($s);
echo "總投票人數(shù): ".$vote[0]."
";
echo "CSI.S7: ".$vote[1]."
";
echo "Mr.Doctor: ".$vote[2]."
";
echo "House Doctor: ".$vote[3]."
";
echo "24hours: ".$vote[4]."
";
?>
圖片驗證MK
數(shù)據(jù)庫操作MK
首先需要兩個頁面1.config.inc.php代碼:
?>
另一個就是數(shù)據(jù)庫操作類頁面了dbclass.php
dbhost=$dbhost;
$this->dbuser=$dbuser;
$this->password=$password;
$this->dbname=$dbname;
}
//創(chuàng)建MYSQL連接
function mycon(){
@mysql_connect($this->dbhost,$this->dbuser,$this->password);
}
//選擇相應(yīng)的數(shù)據(jù)庫
function selectdb(){
@mysql_select_db($this->db);
}
//創(chuàng)建數(shù)據(jù)庫連接并選擇相應(yīng)數(shù)據(jù)庫
function createcon(){
mysql_connect($this->dbhost,$this->dbuser,$this->password);
mysql_query("SET NAMES 'GBK'");//這是解決亂碼的關(guān)鍵哦,LINUX下改為UTF8
mysql_select_db($this->dbname);
}
//執(zhí)行SQL語句,并返回結(jié)果集
function fetch_array($sql){
$result=mysql_query($sql);
return mysql_fetch_array($result);
}
//執(zhí)行SQL語句
function query($sql){
return mysql_query($sql);
}
//取得結(jié)果集數(shù)組
function loop_query($result){
return mysql_fetch_array($result);
}
//關(guān)閉數(shù)據(jù)庫連接
function close() {
return mysql_close();
}
}
?>
下面講下用法:
如果一個頁面要涉及數(shù)據(jù)庫操作,請這樣使用:
include('inc/config.inc.php');//包含數(shù)據(jù)庫基本配置信息
include('inc/dbclass.php');//包含數(shù)據(jù)庫操作類
//以下以插入一條數(shù)據(jù)為例說明,其他操作用法相似
//-----------------------------------------------------------------------------------
$db=new db;//從數(shù)據(jù)庫操作類生成實例,OOP還是好啊
$db->mysql($dbhost,$dbuser,$dbpassword,$dbname);//調(diào)用連接參數(shù)函數(shù)
$db->createcon();//調(diào)用創(chuàng)建連接函數(shù)
//-----------------------------------------------------------------------------------
//開始插入數(shù)據(jù)
//-----------------------------------------------------------------------------------
$addsql="insert into cr_userinfo values(0,'$username','$userpwd','$time',50,1,'$userquestion','$useranswer')";
$db->query($addsql);
echo" 恭喜您,注冊成功!請點擊這里登錄!";
$db->close();//關(guān)閉數(shù)據(jù)庫連接
?>
圖片上傳MK
lengshuye.3322.org
上傳文件:
允許上傳的文件類型為: //implode將數(shù)組元素用“,”分開
if(!in_array($file["type"], $uptypes)) //in_array -- 檢查數(shù)組中是否存在某個值
//檢查文件類型
{
echo "文件類型不符!".$file["type"];
exit;
}
if(!file_exists($destination_folder)) //file_exists -- 檢查文件或目錄是否存在
mkdir($destination_folder);
$filename=$file["tmp_name"];
$image_size = getimagesize($filename);
$pinfo=pathinfo($file["name"]);//pathinfo -- 返回文件路徑的信息
$ftype=$pinfo["extension"];//extension表示后綴,例如:gif jpg
$destination = $destination_folder.time().".".$ftype;
if (file_exists($destination) && $overwrite != true)
{
echo "同名文件已經(jīng)存在了";
exit;
}
if(!move_uploaded_file ($filename, $destination))//move_uploaded_file -- 將上傳的文件移動到新位置
{
echo "移動文件出錯";
exit;
}
$pinfo=pathinfo($destination);
$fname=$pinfo["basename"];
echo " 已經(jīng)成功上傳
文件名: ".$destination_folder.$fname."
";
echo " 寬度:".$image_size[0];
echo " 長度:".$image_size[1];
echo "
大小:".$file["size"]." bytes";
if($watermark==1)
{
$iinfo=getimagesize($destination,$iinfo);
$nimage=imagecreatetruecolor($image_size[0],$image_size[1]);//imagecreatetruecolor -- 新建一個真彩色圖像
$white=imagecolorallocate($nimage,255,255,255);//imagecolorallocate -- 為一幅圖像分配顏色
$black=imagecolorallocate($nimage,0,0,0);
$red=imagecolorallocate($nimage,255,0,0);
imagefill($nimage,0,0,$white);//imagefill -- 區(qū)域填充
switch ($iinfo[2])
{
case 1:
$simage =imagecreatefromgif($destination);//gif
break;
case 2:
$simage =imagecreatefromjpeg($destination);//jpg
break;
case 3:
$simage =imagecreatefrompng($destination);//png
break;
case 6:
$simage =imagecreatefromwbmp($destination);//bmp
break;
default:
die("不支持的文件類型");
exit;
}
imagecopy($nimage,$simage,0,0,0,0,$image_size[0],$image_size[1]);//imagecopy -- 拷貝圖像的一部分
imagefilledrectangle($nimage,1,$image_size[1]-15,80,$image_size[1],$white);
switch($watertype)
{
case 1: //加水印字符串
imagestring($nimage,2,3,$image_size[1]-15,$waterstring,$black);
break;
case 2: //加水印圖片
$simage1 =imagecreatefromgif("xplore.gif");
imagecopy($nimage,$simage1,0,0,0,0,85,15);
imagedestroy($simage1);//imagedestroy($simage1) 釋放與 $simage1 關(guān)聯(lián)的內(nèi)存,銷毀圖像
break;
}
switch ($iinfo[2])
{
case 1:
//imagegif($nimage, $destination);
imagejpeg($nimage, $destination);//imagejpeg -- 以 JPEG 格式將圖像輸出到瀏覽器或文件
break;
case 2:
imagejpeg($nimage, $destination);
break;
case 3:
imagepng($nimage, $destination);
break;
case 6:
imagewbmp($nimage, $destination);
//imagejpeg($nimage, $destination);
break;
}
//覆蓋原上傳文件
imagedestroy($nimage);
imagedestroy($simage);
}
if($imgpreview==1)
{
echo "
圖片預(yù)覽:
";
echo "";
}
}
?>
隨機顯示圖片
圖片目錄$url不存在!請重新設(shè)置!";
?>
數(shù)據(jù)庫分頁
/*
Author:默默
Date :2006-12-03
*/
$page=isset($_GET['page'])?intval($_GET['page']):1; //這句就是獲取page=18中的page的值,假如不存在page,那么頁數(shù)就是1。
$num=10; //每頁顯示10條數(shù)據(jù)
$db=mysql_connect("host","name","pass"); //創(chuàng)建數(shù)據(jù)庫連接
$select=mysql_select_db("db",$db); //選擇要操作的數(shù)據(jù)庫
/*
首先咱們要獲取數(shù)據(jù)庫中到底有多少數(shù)據(jù),才能判斷具體要分多少頁,具體的公式就是
總數(shù)據(jù)數(shù)除以每頁顯示的條數(shù),有余進一。
也就是說10/3=3.3333=4 有余數(shù)就要進一。
*/
$total=mysql_num_rows(mysql_query("select * from table")); //查詢數(shù)據(jù)的總數(shù)
$pagenum=ceil($total/$num); //獲得總頁數(shù)
//假如傳入的頁數(shù)參數(shù)大于總頁數(shù),則顯示錯誤信息
If($page>$pagenum || $page == 0){
Echo "Error : Can Not Found The page .";
Exit;
}
$offset=($page-1)*$num; //獲取limit的第一個參數(shù)的值,假如第一頁則為(1-1)*10=0,第二頁為(2-1)*10=10。
$info=mysql_query("select * from table limit $offset,$num"); //獲取相應(yīng)頁數(shù)所需要顯示的數(shù)據(jù)
While($it=mysql_fetch_array($info)){
Echo $it['name']."
";
} //顯示數(shù)據(jù)
For($i=1;$i$i":"$i";
Echo $show." ";
}
/*顯示分頁信息,假如是當(dāng)頁則顯示粗體的數(shù)字,其余的頁數(shù)則為超連接,假如當(dāng)前為第三頁則顯示如下
1 2 3 4 5 6
*/
?>
本文來自ChinaUnix博客,如果查看原文請點:http://blog.chinaunix.net/u1/37575/showart_295360.html |
|