<html>
<head>
<meta charset="utf-8"> <title>文件上传</title>
<script type="text/javascript" src="jquery/jquery-1.9.0.js"></script>
</head>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
<div>
<img src="" alt="" style="width: 200px;height: 200px" id="showImg">
</div>
<div>
<label for="file">文件名:</label>
<input type="file" name="file" id="file"> <script type="text/javascript">
$('#file').change(function() {
$("#showImg").attr("src", window.URL.createObjectURL(this.files[0]));
}); </script>
</div>
<div>
<label for="info">描述:</label>
<input type="text" name="info" id="info">
</div>
<input type="submit" name="submit" value="提交">
</form>
</body>
</html>
<?php
echo "<pre>";
print_r($_POST); print_r($_FILES); echo "</pre>"; echo "<hr>";
if ($_FILES["file"]["error"] > 0){
echo "错误:" . $_FILES["file"]["error"] . "<br>";
}else{
echo "上传文件名: " . $_FILES["file"]["name"] . "<br>";
echo "文件类型: " . $_FILES["file"]["type"] . "<br>";
echo "文件大小: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "文件临时存储的位置: " . $_FILES["file"]["tmp_name"]."<br>"; $ext = explode(".", $_FILES["file"]["name"]);
echo "文件后缀: " . end($ext);
if (file_exists("upload/" . $_FILES["file"]["name"])){
echo $_FILES["file"]["name"] . " 文件已经存在。 ";
}else{
}
}