PHP:简单的文件上传页面,文件存储到本地

<meta http-equiv="Content-type"  Content="text/html;charset=UTF-8;" />
<!DOCTYPE html>
<br>
<center><font size=6 face="华文楷体" color="blue">PHP--文件上传--PHP</font></center><br>
<form enctype="multipart/form-data" action="" method="post">
<center><input type="file" name="myFile">
<input type="submit" name="up" value="上传文件"> </center><br>
</form>


    if($_POST['up'])
    {
        if($_FILES['myFile']['error']>0)
            echo "
"."错误:".$_FILES['myFile']['error']."
"
; else { if($_FILES['myFile']['size']>0 && $_FILES['myFile']['size']<1024*1024*2) { $dir='./image/'; if(!is_dir($dir)) mkdir($dir); $tmp_filename=$_FILES['myFile']['tmp_name']; $filename=$_FILES['myFile']['name']; $rand=rand(100,999); $filename=date('YmdHis').$rand.$filename; if(is_uploaded_file($tmp_filename)) { if(move_uploaded_file($tmp_filename,"$dir$filename")) { echo "
"."文件上传成功!"."
"
; echo "
"."文件大小为:".($_FILES['myFile']['size']/1024)."KB"."
"
; } else echo "
"."上传文件失败!"."
"
; } } else echo "
"."文件大小超过了2MB!"."
"
; } } ?>

你可能感兴趣的:(PHP)