GWibisono

my editor

Aug 3rd, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.51 KB | None | 0 0
  1. <?php
  2. $a=explode("/",$_SERVER[PHP_SELF]);
  3. $my=$a[sizeof($a)-1];
  4. if($_POST)
  5. {
  6.     foreach($_POST as $n=>$v)$$n=trim($v);
  7. }
  8.  
  9. if($_POST['act']=='new')
  10. {
  11.     $fp = fopen($f, 'w');
  12.     fwrite($fp,"");
  13.     fclose($fp);
  14.     header('location:'.$_SERVER[HTTP_REFERER]);
  15.     die();
  16. }
  17.  
  18. if($_POST['act']=='save')
  19. {  
  20.     //rename
  21.     $pos=strrpos($f,".");
  22.     if ($pos === false){
  23.         $f2=$f.".".mktime();
  24.     }else{
  25.         $f2=substr($f,0,-$pos).mktime().".".
  26.             substr($f,-$pos);
  27.     }
  28.      
  29.     //.".".mktime()
  30.     copy($f,$f2);
  31.     $fp = fopen($f, 'w');
  32.     fwrite($fp, $con);
  33.     fclose($fp);
  34.     header('location:'.$_SERVER[HTTP_REFERER]);
  35.     die();
  36. }
  37.  
  38. if($_GET['f'])
  39. {
  40.     $s.="EDIT: <form method='post'>\n<input type=hidden name=f value='".
  41.         $_GET['f']."'><input type=hidden name=act value='save'>";
  42.     $t=htmlspecialchars(file_get_contents($_GET['f']));
  43.     $s.="<textarea name='con' cols='80' rows=10>$t</textarea>";
  44.     $s.="<br><input type=submit value='save'>";
  45.     $s.="</form>";
  46.    
  47. }
  48.  
  49. $s.="FILE BARU : <form method='post'>\n<input type=hidden name=act value='new'>";
  50.     $s.="<input type=text name=f  />";
  51.     $s.="<input type=submit value='buat file baru'>";
  52. $s.="</form>";
  53.        
  54. if ($handle = opendir('.'))
  55. {
  56.     $s.="<ol>";
  57.     /* This is the correct way to loop over the directory. */
  58.     while (false !== ($entry = readdir($handle)))
  59.     {
  60.         if($entry=='.'||$entry=='..'||is_dir($entry)||$entry==$my)
  61.         {
  62.             continue;
  63.         }
  64.         $s.="<li><a href='?f=$entry'>$entry</a>.</li>\n";
  65.     }
  66.     $s.="</ol>";   
  67.     closedir($handle);
  68.    
  69. }
  70. echo $s;
  71.  
  72.  //print_r($_SERVER);
Advertisement
Add Comment
Please, Sign In to add comment