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

时间:2008-5-31    作者:Deri    分类: 分享


   <p>  如何实现文件上传 ?</p><p><code><HTML><br /><HEAD><br /><TITLE>文件上传界面</TITLE><br /></HEAD><br /><BODY><TABLE><CENTER><br /><?<br />if($UploadAction){<br />$UploadAction=0;<br />$TimeLimit=60;<br />/*设置超时限制时间默认时间为 30s,设置为0时为不限时 */<br />set_time_limit($TimeLimit);<br />If(($Upfile != "none")&&<br />($Upfile != ""))<br />{<br />$Filepath="d:webwebphp  est"; //上载文件存放路径<br />$FileName=$Filepath.$Upfile_name;<br />if($Upfile_size <1024) //上载文件大小<br />{$FileSize = (string)$Upfile_size . "字节";}<br />elseif($Upfile_size <(1024 * 1024))<br />{<br />$FileSize = number_format((double)($Upfile_size / 1024), 1) . " KB";<br />}<br />else<br />{<br />$FileSize = number_format((double)($Upfile_size/(1024*1024)),1)."MB";<br />}<br />if(!file_exists($FileName))<br />{<br />if(copy($Upfile,$FileName))<br />{unlink($Upfile);<br />echo "<br><br><br />";<br />echo "文件 $Upfile_name 已上载成功!";<br />echo "<br><br><br />";<br />echo "文件位置:$FileName";<br />echo "<br><br><br />";<br />echo "文件大小:$FileSize";<br />echo "<br><br><br />";<br />}<br />else<br />{echo "文件 $Upfile_name上载失败!"; }<br />}<br />else<br />{echo "文件 $Upfile_name已经存在!"; }<br />}<br />else<br />{echo "你没有选择任何文件上载!"; }<br />set_time_limit(30); //恢复默认超时设置<br />}<br />?><br /><FORM ENCTYPE = "multipart/form-data" NAME = "SubmitForm"<br />ACTION = "default.php" METHOD = "POST"><br /><INPUT TYPE = "hidden" NAME = "MAX_FILE_SIZE" VALUE ="1000000"><br /><INPUT TYPE = "hidden" NAME = "UploadAction" VALUE = "1"><br /><TR><TD><INPUT NAME = "Upfile" TYPE = "file" SIZE = "30"></TD><br /></TR><TR><TD><INPUT NAME = "submit" VALUE = "提交" TYPE = "submit"><br /><INPUT NAME = "reset" VALUE = "重置" TYPE = "reset"></TD><br /></TR></FORM></CENTER></TABLE><br /></BODY><br /></HTML></code></p>