php学习笔记2

  文件管理系统

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8">
</head>
<body>

<?php
    $path = @$_GET["path"];
    if(empty($path)) $path = "./";
    
    $filterList = array("filesystem.php");

    $filename = trim($path,"/")."/".@$_GET["name"];

    switch(@$_GET["action"]) {
        case "del" :
            @unlink($filename);
        break;
        case "add" :
            echo $path;
            if( file_exists($filename) ) {
                die("file exists");
            }else{
                $f = fopen($filename,"w");
                fclose($f);
            }
            echo $filename;
        break;
        case "edit" :
            $fielinfo = file_get_contents($filename);
            echo "<br>";
            echo "<form action='filesystem.php?action=update' method='post'>";
            echo "<textarea name='content'> {$fielinfo} </textarea>";
            echo "<input type='hidden' value='{$filename}' name='name'>";
            echo "<input type='submit'>";
            echo "</form>";
            break;
        break;
        case "update" :
            $content = $_POST["content"];
            $f = $_POST["name"];
            file_put_contents($f, $content);
        break;
        default:

    }
    if( !file_exists($path) || !is_dir($path) ) {
        die( $path."目录无效" );
    };
    echo "<p>{$path}目录</p>";
    echo "<p>  <form action='filesystem.php' method='get'> 创建文件 : <input type='hidden' name='path' value='{$path}'><input type='hidden' name='action' value='add'></input> <input name='name'><input type='submit'></input></form></p>";
    echo "<table border='1'>";

    $dir = opendir($path);
    if($dir) {
        $i = 0;
        while($f = readdir($dir)) {
            if($f=="."|| $f=="..") continue;
            $file = trim($path, "/")."/".$f;
            $i++;
            echo "<tr>";
            echo "<td> {$i} </td>";
            echo "<td> {$f} </td>";
            echo "<td>".filetype($file)."</td>";
            echo "<td>".filesize($file)."</td>";
            echo "<td>".date("Y-m-d",filectime($file))."</td>";
            if( !in_array($f, $filterList) ) {
                echo "<td><a href='filesystem.php?path={$path}&name={$f}&action=del'>删除</a></td>";
                echo "<td><a href='filesystem.php?path={$path}&name={$f}&action=edit'>编辑</a></td>";
            }
            echo "</tr>";
        }
    }
    closedir($dir);
    echo "</table>";
?>
</body>
</html>

  只能管理文件, 不能管理目录..

  打印万年历, 这个666了, 逻辑刚开始没搞懂...:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8">
</head>
<body>
<?php
    @$y = $_GET["Y"] ? $_GET["Y"] : date("Y");
    @$m = $_GET["m"] ? $_GET["m"] : date("m");

    echo $y;
    echo $m;

    $t = date("t",mktime(0,0,0,$m, 1, $y));
    $w = date("w",mktime(0,0,0,$m, 1, $y));
    $arr = array("周一","周二","周三","周四","周五","周六","周日");
    echo "<h4>{$y}年{$m}月</h4>";
    echo "<table><thead><tr>";
    foreach($arr as $d) {
        echo "<td>{$d}</td>";
    }
    echo "</tr></thead><tbody>";
    echo "<tr>";
    $temp = 1;
    for($i=1; $i<$t+1; ) {
        for($j=0;$j<7;$j++) {
            if($temp<($w+1)) {
                echo "<td>_</td>";
                $temp++;
                continue;
            }
            if($i<$t+1 ) {
                echo "<td>{$i}</td>";
                $i++;
            }
        }
        echo "</tr><tr>";
    }
    echo "</tr>";
    echo "</tbody>";
    echo "</table>";
    
?>
</body>
</html>

   php高版本还支持定界符, 相对于js中的``符号, 内部的代码会原封不动的输出:

<?php

$str = 'abc';
print<<<EOF
{$str}efg
EOF;

?>

  foreach循环输出object对象的key和值:

<?php

$arr = array("a"=>"aa", "b"=>"bb", "c"=>"cc");
foreach( $arr as $k => $val) {
    echo $k ."+";
    echo $val. "\n";
}

?>

  $GLOBALS['var'] 是外部的全局变量$var本身。
  global $var 是外部$var的同名引用或者指针。(错误:是个别名引用而已,非指针!!!)

  把字符串转化为base64编码:   

<?php

echo base64_encode("string");

?>

 

厦门点燃未来网络科技有限公司, 是厦门最好的微信应用, 小程序, 微信网站, 公众号开发公司

EOF

posted @ 2017-07-24 15:44  方方和圆圆  阅读(190)  评论(0编辑  收藏  举报

再过一百年, 我会在哪里?