<?php
##author :Androidyue
##sina @androidyue
##Blog http://blog.csdn.net/BossDarcy
##源码具体讲解 http://blog.csdn.net/BossDarcy/archive/2010/12/20/6086082.aspx
if
(is_uploaded_file($_FILES[
"uploadfile"
][
"tmp_name"
])){
$upfile=$_FILES[
"uploadfile"
];
$name=$upfile[
"name"
];
$type=$upfile[
"type"
];
$size=$upfile[
"size"
];
$tmp_name=$upfile[
"tmp_name"
];
$error=$upfile[
"error"
];
switch
($type){
case
"image/jpg"
: $ok=1;
break
;
case
"image/jpeg"
: $ok=1;
break
;
case
"image/gif"
: $ok=1;
break
;
default
:$ok=0;
break
;
}
if
($ok&&$error==
'0'
){
move_uploaded_file($tmp_name,
'up/'
.$name);
echo
"<script language=\"javascript\">alert('succeed')</script>"
;
}
else
{
echo
"<script language=\"javascript\">alert('failed')</script>"
;
}
}
?>
<!--设置提交文件的表单-->
<form enctype=
"multipart/form-data"
method=
"post"
name=
"uploadform"
>
<input type=
"file"
name=
"uploadfile"
value=
"Upload File"
>
<input type=
"submit"
name=
"submit"
value=
"Upload"
>
</form>