在php中,处理上传文件信息也是很方便的,以下是一个简单的示例,有助于大家理解php是如何接收与处理上传文件信息的。
代码:
<?php /** * php 处理上传文件 * by www.jb200.com */ $maxsize=28480; if (!$HTTP_POST_VARS['submit']) { $error=" "; } if (!is_uploaded_file($HTTP_POST_FILES['upload_file']['tmp_name']) AND !isset($error)) { $error = "<b>上传文件不能为空!</b><br /><br />"; unlink($HTTP_POST_FILES['upload_file']['tmp_name']); } if ($HTTP_POST_FILES['upload_file']['size'] > $maxsize AND !isset($error)) { $error = "<b>错误:上传文件大小必须小于 $maxsize 字节.</b><br /><br />"; unlink($HTTP_POST_FILES['upload_file']['tmp_name']); } if (!isset($error)) { move_uploaded_file($HTTP_POST_FILES['upload_file']['tmp_name'], "uploads/".$HTTP_POST_FILES['upload_file']['name']); print "上传成功。"; exit; } else { echo ("$error"); } ?> <html> <head> </head> <body> <form action="<?php echo(htmlspecialchars($_SERVER['PHP_SELF']))?>" method="post" enctype="multipart/form-data"> 选择上传文件:<br /> <input type="file" name="upload_file" size="80"> <br /> <input type="submit" name="submit" value="开始上传"> </form> </body> </html>