index.php
<form enctype="multipart/form-data" method="POST" action="upload.php">
<input type=file name=upfile><input type=submit value=提交>
</form>
upload.php
<?php
date_default_timezone_set('Asia/Shanghai');
$uptypes=array('image/JPG', //上传文件类型列表
'image/jpeg',
'image/png',
'image/pjpeg',
'image/gif',
'image/bmp',
'application/x-shockwave-flash',
//"video/x-ms-asf",
//"video/avi",
"application/msword" ,
//"application/zip",
//"application/vnd.ms-excel" ,
//"application/vnd.ms-powerpoint",
//"application/x-msaccess",
//"audio/wav" ,
//"audio/mpeg3" ,
//"video/mpeg" ,
//"application/rtf" ,
//"text/html" ,
"text/plain" ,
//"application/octet-stream" ,
'image/x-png');
$filename=$_FILES["upfile"]["name"];
$tmp_name=$_FILES["upfile"]["tmp_name"];
$ftype=$_FILES["upfile"]["type"];
$fsize=$_FILES["upfile"]["size"];
$upload_dir="H:/MyPHP/up/";
echo $_SERVER['DOCUMENT_ROOT'];
echo "<br/>";
echo $filename;
echo "<br/>";
echo $tmp_name;
echo "<br/>";
if(!file_exists($upload_dir)){
mkdir($upload_dir);
}
echo $ftype;
echo "<br/>";
$pinfo=pathinfo($filename);
$extension=$pinfo[extension];
echo $extension;
echo "<br/>";
if(!in_array($ftype, $uptypes))
{
echo "文件格式不正确";
exit;
}
$newname=date(Ymdhis).".".$extension;
echo $newname;
echo "<br/>";
echo $fsize;
echo "<br/>";
if($fsize>1000000){
echo "文件太大";
exit;
}
if(move_uploaded_file($tmp_name,$upload_dir.$newname)){
echo "上传成功";
}else{
echo "失败";
}
?>