<form name="form_upload" method="post" action="<? echo htmlspecialchars($_SERVER[‘PHP_SELF‘]);?>" enctype="multipart/form-data">
<p><label><b>上传文件</b></label><input type="file" name="file"></p>
<input type="submit" name="Submit" value="确定">
</form>
<?php
if($_POST[‘Submit‘]=="确定")
{
if((($_FILES[‘file‘][‘type‘]=="image/png")||($_FILES[‘file‘][‘type‘]=="image/png")||($_FILES[‘file‘][‘type‘]=="image/png")&&($_FILES[‘file‘][‘size‘]<500000))
)
{
if($_FILES["file"]["error"]>0)
{
echo "Error code:".$_FILES[‘file‘][‘error‘];
}
else
{
echo "upload:".$_FILES[‘file‘][‘name‘];echo "<br/>";
echo "type:".$_FILES[‘file‘][‘type‘];echo "<br/>";
echo "size:".$_FILES[‘file‘][‘size‘]/1024;echo "kb<br/>";
echo "tmp file:".$_FILES[‘file‘][‘name‘];echo "<br/>";
//echo "文件名:".$_FILES[‘file‘][‘name‘];
if(file_exists("uplaod/hadoop.png"))
{
echo $_FILES[‘file‘][‘name‘]."has already exists!";
}
else
{
if(move_uploaded_file($_FILES[‘file‘][‘tmp_name‘],"upload/".$_FILES[‘file‘][‘name‘]))
{
echo "stored in:upload/".$_FILES[‘file‘][‘name‘];
}
else
{
echo "upload failed!";
}
}
}
}//type
else
{
echo "Invalid file!文件类型或大小不符!";
}
}
?>