首页 > 开发 > PHP > 正文

PHP实例:实现文件上传的程序源码

2024-05-04 23:05:43
字体:
来源:转载
供稿:网友
注册会员,创建你的web开发资料库,

如何实现文件上传?

以下为引用的内容:

<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>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表