php文件上传简单示例

来源:互联网 发布:centos连接无线网络 编辑:程序博客网 时间:2024/05/21 19:32
<?php
/*
抛个砖,具体要做成什么样自己做。
*/

if(isset($_FILES['userfile']['tmp_name'
])){
$userfile $_FILES['userfile']['tmp_name']; 
//保存在系统的临时位置
$userfile_name $_FILES['userfile']['name'];
//文件名
$userfile_size $_FILES['userfile']['size'];
//文件大小,字节
$userfile_type $_FILES['userfile']['type'];
//文件类型

if(!is_dir("image")) mkdir ("image"0700
);
$upfile "image/".$userfile_name;
//保存位置
print_r($_FILES
);

//move_uploaded_file($userfile,$upfile);//方法1

if(!copy($userfile,$upfile))
//方法2
{
echo 
"上传失败"
;
exit();
}
echo 
"上传成功"
;
echo 
"<a href=/"#/" onClick=/"window.history.back();/">再上传一张</a>"
;
}
else{
?>
<
html
>
<
head
>
<
meta http-equiv="Content-Type" content="text/html; charset=gb2312"
>
<
title>无标题文档</title
>
</
head
>

<
body
>
<
form action="" method="post" enctype="multipart/form-data" name="form1"
>
  <
input name="MAX_FILE_SIZE" type="hidden" id="MAX_FILE_SIZE" value="1000"
>
  <
input name="userfile" type="file" id="userfile"
>
  <
input type="submit" name="Submit" value="上传"
>
</
form
>
</
body
>
</
html
>
<?
php }?> 

 

 

http://blog.chinaunix.net/u/24375/showart_187025.html

原创粉丝点击