上传页面file1.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>文件上传</title>
</head>
<body>
<form name="form1" method="post" action="upload.php"
enctype="multipart/form-data">
文件:<input type="file" name="newsfile"><br>
<input type="submit" value="上传">
</form>
</body>
</html>
保存页面upload.php
<?php
echo "Upload: " . $_FILES["newsfile"]["name"] . "<br />";
echo "Type: " . $_FILES["newsfile"]["type"] . "<br />";
echo "Size: " . ($_FILES["newsfile"]["size"]) . ";" . ($_FILES["newsfile"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["newsfile"]["tmp_name"] . "<br />";
if ((($_FILES["newsfile"]["type"] == "image/gif") || ($_FILES["newsfile"]["type"] == "image/jpeg") || ($_FILES["newsfile"]["type"] == "image/pjpeg")) && ($_FILES["newsfile"]["size"] < 20000000)) {
if ($_FILES["newsfile"]["error"] > 0) {
echo "Return Code: " . $_FILES["newsfile"]["error"] . "<br />";
} else {
if (file_exists("upload/" . $_FILES["newsfile"]["name"])) {
echo $_FILES["newsfile"]["name"] . " already exists. ";
} else {
move_uploaded_file($_FILES["newsfile"]["tmp_name"], "D:/wamp/www/upload/" . $_FILES["newsfile"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["newsfile"]["name"];
}
}
} else {
echo "Invalid file";
}
?>