主页 > 知识库 > 网络编程 > PHP >

PHP

几段值得初学者研究的PHP代码段(3)

来源:未知 作者:admin 发表于:2009-09-29 11:00  点击:
浏览目录 HTML HEAD TITLE浏览目录/TITLE /HEAD BODY ? // 使用表格浏览目录的结构 print(TABLE BORDER=\1\\n); // 创建表格的头 print(TRfont color='red'\n); print(TH文件名/TH\n); print(TH文件的大小/TH\n); p

浏览目录
<HTML>
<HEAD>
<TITLE>浏览目录</TITLE>
</HEAD>
<BODY>
<?
// 使用表格浏览目录的结构
print("<TABLE BORDER=\"1\">\n");
// 创建表格的头
print("<TR><font color='red'>\n");
print("<TH>文件名</TH>\n");
print("<TH>文件的大小</TH>\n");
print("</font></TR>\n");
$myDirectory = opendir("."); // 建立操作目录的句柄
// 读出目录中的每一个子项
while($entryName = readdir($myDirectory))
{
print("<TR>");
print("<TD>$entryName</TD>");
print("<TD ALIGN=\"right\">");
print(filesize($entryName));
print("</TD>");
print("</TR>\n");
}
closedir($myDirectory); // 关闭目录
print("</TABLE>\n");
?>
</BODY>
</HTML>
PHP相关信息
<HTML>
<HEAD>
<TITLE>PHP相关信息</TITLE>
</HEAD>
<BODY>
<?
phpinfo();
?>
</BODY>
</HTML>
常用的数值判断函数
<HTML>
<HEAD>
<TITLE>常用的数值判断函数</TITLE>
</HEAD>
<BODY>
<?
//判断数组
$colors = array("red", "blue", "green");
if(is_array($colors))
{
print("colors is an array"."<br>");
}
//双精度数判断
$Temperature = 15.23;
if(is_double($Temperature))
{
print("Temperature is a double"."<br>");
}
//整数判断
$PageCount = 2234;
if(is_integer($PageCount))
{
print("$PageCount is an integer"."<br>");
}
//对象判断
class widget
{
var $name;
var $length;
}
$thing = new widget;
if(is_object($thing))
{
print("thing is an object"."<br>");
}
//字符判断
$Greeting = "Hello";
if(is_string($Greeting))
{
print("Greeting is a string"."<br>");
}
?>
</BODY>
</HTML>
文件上传界面
<HTML>
<HEAD>
<TITLE>文件上传界面</TITLE>
</HEAD>
<BODY><TABLE><CENTER>
<?
if($UploadAction){
$UploadAction=0;
$TimeLimit=60;
/*设置超时限制时间默认时间为 30s,设置为0时为不限时 */
set_time_limit($TimeLimit);
If(($Upfile != "none")&&
($Upfile != ""))
{
$Filepath="d:\web\web\php\test"; //上载文件存放路径
$FileName=$Filepath.$Upfile_name;
if($Upfile_size <1024) //上载文件大小
{$FileSize = (string)$Upfile_size . "字节";}
elseif($Upfile_size <(1024 * 1024))
{
$FileSize = number_format((double)($Upfile_size / 1024), 1) . " KB";
}
else
{
$FileSize = number_format((double)($Upfile_size/(1024*1024)),1)."MB";
}
if(!file_exists($FileName))
{
if(copy($Upfile,$FileName))
{unlink($Upfile);
echo "<br><br>\n";
echo "文件 $Upfile_name 已上载成功!";
echo "<br><br>\n";
echo "文件位置:$FileName";
echo "<br><br>\n";
echo "文件大小:$FileSize";
echo "<br><br>\n";
}
else
{echo "文件 $Upfile_name上载失败!"; }
}
else
{echo "文件 $Upfile_name已经存在!"; }
}
else
{echo "你没有选择任何文件上载!"; }
set_time_limit(30); //恢复默认超时设置
}
?>
<FORM ENCTYPE = "multipart/form-data" NAME = "SubmitForm"
ACTION = "default.php" METHOD = "POST">
<INPUT TYPE = "hidden" NAME = "MAX_FILE_SIZE" VALUE ="1000000">
<INPUT TYPE = "hidden" NAME = "UploadAction" VALUE = "1">
<TR><TD><INPUT NAME = "Upfile" TYPE = "file" SIZE = "30"></TD>
</TR><TR><TD><INPUT NAME = "submit" VALUE = "提交" TYPE = "submit">
<INPUT NAME = "reset" VALUE = "重置" TYPE = "reset"></TD>
</TR></FORM></CENTER></TABLE>
</BODY>
</HTML>

有帮助
(248)
77%
没帮助
(74)
23%