php上傳、管理照片示例
更新時(shí)間:2006年10月09日 00:00:00 作者:
<!--上傳照片示例 upimage.php
功能:上傳照片,顯示上傳人、上傳時(shí)間、圖片名稱、圖片大小、圖片說(shuō)明。
說(shuō)明:1.有一些主頁(yè)空間可能不支持上傳后的臨時(shí)文件操作,那只能換一個(gè)試試?yán)病?
2.程序可以自動(dòng)新建文檔photo.txt和目錄image,若不能正常運(yùn)行,請(qǐng)自己新建一個(gè)文檔photo.txt(和upimage.php在同一個(gè)目錄下)和目錄image.
3.可以到我的主頁(yè)上測(cè)試一下 http://medonline.51.net/upload/upimage.php
-->
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<TITLE>上傳照片</TITLE>
<style type="text/css">
<!--
.white12 { font-size: 12pt; color: #FFFFFF; text-decoration: none}
.blue10 { font-size: 10pt; color: #99CCFF; text-decoration: none}
.black10 { font-size: 10pt; text-decoration: none}
-->
</style>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<?php
if ($upload){ //如果點(diǎn)擊"上傳",則執(zhí)行此php代碼部分
if ($picurl=="none"){
echo "你沒(méi)有上傳任何文件.";
exit; //如果沒(méi)有上傳文件,則退出程序
}
$v=opendir("image");
if ($v==0)
{ mkdir("image"); //若目錄不存在,則新建一個(gè)
$v=opendir("image"); //取得目錄handle
}
$up=copy("$picurl","image/$picurl_name"); //關(guān)鍵一步,將臨時(shí)文件復(fù)制到image目錄下
if($up==1)
{
//文件操作
$fp=fopen("photo.txt","a");//打開(kāi)文件,以添加方式寫(xiě)入留言
//初始化寫(xiě)入內(nèi)容
$mydate=date("Y年m月d日 h:i A");
$photonote=nl2br($photonote);//將換行字元轉(zhuǎn)成 <br>。
$text="照片名:<a href='image/$picurl_name' target='_blank'>$picurl_name</a> <br>照片大小:$picurl_size byte<br> 照片說(shuō)明:<BR><span class='blue10'>$photonote</span><br> <div align='right'>上傳人: $user($mydate)</div><hr>";
//寫(xiě)入內(nèi)容
fwrite($fp,$text,strlen($text)); //strlin計(jì)算$text的字串長(zhǎng)度
fclose($fp);
echo "文件上傳成功!<BR>";
unlink ($picurl); //從臨時(shí)文件夾中刪除檔案$picurl
closedir ($v); //關(guān)閉目錄handle
}
else
{echo "文件上傳失敗."; exit;} //若上傳失敗,則退出程序
}
?>
<table width="71%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr bgcolor="#6699FF">
<td>
<div align="center" class="white12">所有照片</div>
</td>
</tr>
<tr>
<td class="black10">
<?php
//顯示以往上傳照片信息
readfile ("photo.txt");
?>
</td>
</tr>
<tr bgcolor="#6699FF">
<td>
<div align="center" class="white12">上傳照片</div>
</td>
</tr>
<tr>
<td>
<form action="upimage.php" method="post" enctype="multipart/form-data" name="UL">
<!--注意:這里必須加上‘enctype="multipart/form-data" ',否則不會(huì)產(chǎn)生上
傳動(dòng)作-->
<div align="center" class="black10">圖片源文件:
<input type="file" name="picurl" size="15" accept="image/x-png,image/gif,image/jpeg">
<br>
照片說(shuō)明:(不超過(guò)50個(gè)字)<br>
<textarea name="photonote" cols="50" rows="5"></textarea>
<br>上傳人:
<input type="text" name="user" size="10" maxlength="10">
<br>
<input type="Submit" name="upload" value="上傳">
<input type="reset" name="Reset" value="重寫(xiě)">
</div>
</form>
<div align="center" class="blue10"><a href="javascript:history.back()"> 返回</a> </div>
</td>
</tr>
</table>
</BODY>
</HTML>
【本文版權(quán)歸作者與奧索網(wǎng)共同擁有,如需轉(zhuǎn)載,請(qǐng)注明作者及出處】
功能:上傳照片,顯示上傳人、上傳時(shí)間、圖片名稱、圖片大小、圖片說(shuō)明。
說(shuō)明:1.有一些主頁(yè)空間可能不支持上傳后的臨時(shí)文件操作,那只能換一個(gè)試試?yán)病?
2.程序可以自動(dòng)新建文檔photo.txt和目錄image,若不能正常運(yùn)行,請(qǐng)自己新建一個(gè)文檔photo.txt(和upimage.php在同一個(gè)目錄下)和目錄image.
3.可以到我的主頁(yè)上測(cè)試一下 http://medonline.51.net/upload/upimage.php
-->
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<TITLE>上傳照片</TITLE>
<style type="text/css">
<!--
.white12 { font-size: 12pt; color: #FFFFFF; text-decoration: none}
.blue10 { font-size: 10pt; color: #99CCFF; text-decoration: none}
.black10 { font-size: 10pt; text-decoration: none}
-->
</style>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<?php
if ($upload){ //如果點(diǎn)擊"上傳",則執(zhí)行此php代碼部分
if ($picurl=="none"){
echo "你沒(méi)有上傳任何文件.";
exit; //如果沒(méi)有上傳文件,則退出程序
}
$v=opendir("image");
if ($v==0)
{ mkdir("image"); //若目錄不存在,則新建一個(gè)
$v=opendir("image"); //取得目錄handle
}
$up=copy("$picurl","image/$picurl_name"); //關(guān)鍵一步,將臨時(shí)文件復(fù)制到image目錄下
if($up==1)
{
//文件操作
$fp=fopen("photo.txt","a");//打開(kāi)文件,以添加方式寫(xiě)入留言
//初始化寫(xiě)入內(nèi)容
$mydate=date("Y年m月d日 h:i A");
$photonote=nl2br($photonote);//將換行字元轉(zhuǎn)成 <br>。
$text="照片名:<a href='image/$picurl_name' target='_blank'>$picurl_name</a> <br>照片大小:$picurl_size byte<br> 照片說(shuō)明:<BR><span class='blue10'>$photonote</span><br> <div align='right'>上傳人: $user($mydate)</div><hr>";
//寫(xiě)入內(nèi)容
fwrite($fp,$text,strlen($text)); //strlin計(jì)算$text的字串長(zhǎng)度
fclose($fp);
echo "文件上傳成功!<BR>";
unlink ($picurl); //從臨時(shí)文件夾中刪除檔案$picurl
closedir ($v); //關(guān)閉目錄handle
}
else
{echo "文件上傳失敗."; exit;} //若上傳失敗,則退出程序
}
?>
<table width="71%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr bgcolor="#6699FF">
<td>
<div align="center" class="white12">所有照片</div>
</td>
</tr>
<tr>
<td class="black10">
<?php
//顯示以往上傳照片信息
readfile ("photo.txt");
?>
</td>
</tr>
<tr bgcolor="#6699FF">
<td>
<div align="center" class="white12">上傳照片</div>
</td>
</tr>
<tr>
<td>
<form action="upimage.php" method="post" enctype="multipart/form-data" name="UL">
<!--注意:這里必須加上‘enctype="multipart/form-data" ',否則不會(huì)產(chǎn)生上
傳動(dòng)作-->
<div align="center" class="black10">圖片源文件:
<input type="file" name="picurl" size="15" accept="image/x-png,image/gif,image/jpeg">
<br>
照片說(shuō)明:(不超過(guò)50個(gè)字)<br>
<textarea name="photonote" cols="50" rows="5"></textarea>
<br>上傳人:
<input type="text" name="user" size="10" maxlength="10">
<br>
<input type="Submit" name="upload" value="上傳">
<input type="reset" name="Reset" value="重寫(xiě)">
</div>
</form>
<div align="center" class="blue10"><a href="javascript:history.back()"> 返回</a> </div>
</td>
</tr>
</table>
</BODY>
</HTML>
【本文版權(quán)歸作者與奧索網(wǎng)共同擁有,如需轉(zhuǎn)載,請(qǐng)注明作者及出處】
相關(guān)文章
PHP實(shí)現(xiàn)分頁(yè)的一個(gè)示例
PHP實(shí)現(xiàn)分頁(yè)的一個(gè)示例...2006-10-10
PHP數(shù)組中頭部和尾部添加元素的方法(array_unshift,array_push)
對(duì)于數(shù)字索引數(shù)組來(lái)說(shuō),通過(guò) array_push()函數(shù)向數(shù)組中尾部添加元素,array_unshift頭部添加元素,需要的朋友可以參考下2017-04-04
一步一步學(xué)習(xí)PHP(5) 類和對(duì)象
OO的強(qiáng)大我不想再多說(shuō),如果你不認(rèn)同OO,那么當(dāng)你放眼當(dāng)前流行的語(yǔ)言,有哪個(gè)又不支持OO的,也許這個(gè)很有說(shuō)服力了吧。2010-02-02

