複製代碼 代碼如下:<HTML>
<HEAD>
<TITLE>檔案上傳</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></HEAD>
<BODY>
<?
$UploadedFile=$_FILES['UploadedFile']['tmp_name'];
$UploadedFile_name=$_FILES['UploadedFile']['name'];
$isTrue=false;
if($UploadedFile)
{
$store_dir=$_SERVER['DOCUMENT_ROOT'];
$accept_overwrite = 1;
$isTrue=true;
}
$fileName = date("YmtHis").$UploadedFile_name;
if (file_exists($store_dir . $fileName))
{
echo "存在相同檔案名稱的檔案";
}
$mytype =array(".jpg",".gif",".png");
$filetype=substr($_FILES['UploadedFile']['name'],strrpos($_FILES['UploadedFile']['name'],"."));
$typecount=0;
if($isTrue)
{
for($i=0;$i<count($mytype);$i++)
{
if($filetype==$mytype[$i])
{
$typecount++;
}
}
if($typecount>0)
{
if($_FILES['UploadedFile']['size']<1048576)
{
$b=move_uploaded_file($UploadedFile,$store_dir.$fileName);
if($b)
{
echo "<HR>\n";
echo "原檔案資訊:<br/>";
echo "名稱:".$_FILES['UploadedFile']['name']."<BR>\n";
echo "大小:".$_FILES['UploadedFile']['size']."<BR>\n";
echo "類型:".$_FILES['UploadedFile']['type']."<BR>\n";
echo "<HR>\n";
echo "存入資料庫的名稱為:".$fileName;
echo "<HR>\n";
}
}
else
{
echo "檔案大小不準超過1兆.";
}
}
else
{
echo "不準上傳次類型檔案!";
}
}
?>
<FORM ENCTYPE="multipart/form-data" ACTION="<?php echo $PHP_SELF ?>" METHOD="post">
<INPUT NAME="UploadedFile" TYPE="file" size='15'>
<INPUT TYPE="submit" VALUE="上傳檔案">
</FORM>
</BODY>
</HTML>