用于文件操作的超全局变量和函数 
变量和函数:
$_FILES:超全局变量,获得post上传的文件,是个二重数组。
__DIR__:获得当前服务器端的系统路径。
date(str):获得日期(Y年份,m月份,d日期)。
is_dir(file):判断file是不是目录。
mkdir($path,0777,true):创建目录,参数分别是路径,权限,若文件存在则覆盖员文件。
strchr(str,'.'):获得str中.后的字符串
rand():生成随机数
move_upload_file(f1,f2):把文件f1移到f2位置
  
upload.html 
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>文件上传</title>
</head>
<body>
	<form action="t.php" method="post" enctype="multipart/form-data"> 
		<input type="file" name="pic" />
		<input type="submit" />
	</form>
</body>
</html>
  
t.php 
<?php
	
	if(empty($_FILES)){
		echo "请上传文件";
	}
	else{
		echo $_FILES["pic"]["name"]."<br/>";
		echo $_FILES["pic"]["tmp_name"];
	
	define("PATH", __DIR__);
	echo PATH;   
	$dir1=date("Ym");
	$dir2=date("d");
	$path=PATH."/"."upload"."/images"."/".$dir1."/".$dir2;
	if (is_dir($path)){
		echo "yes";
	}
	else{
		mkdir($path,0777,true);
	}
	$filename=rand(1000000,9000000);
	$filetype=strchr($_FILES["pic"]["name"],'.');
	$filename=$filename.$filetype;
	move_uploaded_file($_FILES["pic"]["tmp_name"], $path.'/'.$filename);
	 
	
}
  
补充:其他文件操作有关的函数 
realpath("..")  	:获得当前目录在服务器的地址realpath('.')等同于		__DIR__
opendir()       	:获得目录
readdir()       	:读取目录
$filename=opendir(".");
while ($row=readdir($filename)) {
	echo $row."<br/>";
	
}
closedir($filename);
is_dir(filename); 					:判断是不是文件夹
$str=file_get_contents("t.php");    :获得t.php的文件内容
 
                
                
                
        
    
 
 |