简单的文件上传代码
index.html
<html>
<head>
<title>文件上传</title>
</head>
<body>
<table>
<form action="file_upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" id="file">
<input type="submit" name="submit" value="提交">
</form>
</table>
</body>
</html>
file_upload.php
<?php
if ($_FILES['file']['size'] < 10000000){
/*此处可对上传文件类型做约束
if (!stristr($_FILES['file']['type'], 'image')){
echo "文件类型上传错误,请重新上传...";
echo '<meta http-equiv="refresh" content="3;url=index.html">';
}
*/
//文件上传服务器端存储目录
$upload_file = './upload/';
if (!is_dir($upload_file)){
mkdir($upload_file);
}
$path = $upload_file . $_FILES['file']['name'];
if (move_uploaded_file($_FILES['file']['tmp_name'], $path)){
echo "文件上传成功,请稍等...";
echo '<meta http-equiv="refresh" content="3;url=index.html">';
}else{
echo "文件上传失败,请重传...";
echo '<meta http-equiv="refresh" content="3;url=index.html">';
}
}else{
echo "文件大小超过上限,请重传...";
echo '<meta http-equiv="refresh" content="3;url=index.html">';
}
?>
//最后修改日期:2011-10-27 2:40