当前位置:首页> PHP教程> php基础
关键字
文章内容
php文件上传示例。。。
 
 
修改时间:[2010/10/16 12:32]    阅读次数:[821]    发表者:[起缘]
 
<?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 }?> 

(非常全面的一个php技术网站, 有相当丰富的文章和源代码.)