1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
- - index.php <?php header("Content-type:text/html;charset=utf-8"); // // 文件包含 // // require include require_once include_once // echo "www.x.com<hr/>"; // require_once "array.php"; //include报错还是执行 // //require报错不执行
// echo "xxxx<hr/>"; // require_once "array.php"; // echo "xxxx<hr/>"; // require_once "array.php"; //只执行一次 // echo "xxxx<hr/>"; // echo realpath("../../"); /* $fileNames = opendir("."); //开文件夹 while($row = readdir($fileNames)) //读文件 { echo $row."<br/>"; }
closedir($fileNames);
if(is_dir("2.php")){ echo "yes"; }else{ echo "no"; } */ // unlink("12313.php"); //删除文件
//file_get_contents() //读取内容 //file_put_contents写入内容
// $str = file_get_contents("array.php");
// var_dump($str);
//递归技巧
/* $path 目录 $lev 层级 进入一层,目录更深,明显显示出来 */ function showDir($path, $lev=0){ $fh = opendir($path); while($row = readdir($fh)){ //如果目录为.和..就跳过 if(($row == '.') || ($row == '..')){ continue; } echo str_repeat("$nbsp;$nbsp;", $lev),$row,'<br />'; //如果目录里还有目录,继续往下读目录 if(is_dir($path.'/'.$row)){ showdir($path.'/'.$row,$lev+1); } } closedir($fh); } showDir('..'); ?>
-- array.php <?php header("Content-type:text/html;charset=utf-8"); // var_dump($_FILES); if(empty($_FILES)){ echo "请上传文件"; }else{ // echo $_FILES['pic']['name']."<br/>"; // echo $_FILES['pic']['tmp_name']."<br/>"; define("PATH",__DIR__); $path = PATH."/"."upload"."/images"; $dir1 = date("Ym"); $dir2 = date("d"); $fullPath = $path."/".$dir1."/".$dir2; if(is_dir($fullPath)) { echo "yes"; }else{ //echo "no"; mkdir($fullPath,0777,true); }
$fileName = rand(100000,999999); $fileType = strrchr($_FILES['pic']['name'], "."); $fileName = $fileName.$fileType;
move_uploaded_file($_FILES['pic']['tmp_name'], $fullPath."/".$fileName); } ?>
- -3.php <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>测试文件上传</title> </head> <body>
<form action="array.php" method="post" enctype="multipart/form-data"> <input type="file" name="pic" /> <input type="submit" /> </form>
</body> </html>
-- 4.php <?php //D:\phpstudy pro\WWW //echo __DIR__."<br/>"; //D:\phpstudy pro //echo dirname(__DIR__); define("PATH",__DIR__); $path = PATH."/"."upload"."/images"; $dir1 = date("Ym"); $dir2 = date("d"); $fullPath = $path."/".$dir1."/".$dir2; if(is_dir($fullPath)) { echo "yes"; }else{ //echo "no"; mkdir($fullPath,0777,true); } ?>
- - 6.php <?php $a=1; $b=2; $fh = opendir('..'); while($row = readdir($fh)) { echo $row."<br/>"; } ?>
|
评论