Jump to content

flat file create/edit/delete


soddengecko

Recommended Posts

Hi all

I am trying to create a small app that will create a text file with a given name and content. these text files will then need to be updateable/editable and deletable.

the purpose of this is not for a database but for creating text files with data/info that is grabbed from the web or just to make some notes in a text file.

So far i have made the creation page and am able to make a text file with any name and add data to that file. I also have a small script that scans the folder and lists all the files in that folder with a link to open the file.

on the view page i have

name_of_file.txt
(view | edit | delete | upload)

so far, only view works. what i would like to know is how to get the edit and delete functions working??? the upload function can wait for now. (the app will be used locally, and upload will upload the file to a given remote directory for web viewing)

can anyone help me out?
Link to comment
https://forums.phpfreaks.com/topic/34544-flat-file-createeditdelete/
Share on other sites

got it working a treat. i do however, have a slight problem. when i click delete, the file is removed but the page still displays the file and it does not refresh. i have tried using a header function to refresh but i get the cannot modify headers error and the page does not refresh at all.

here is the code

<?php



  function file_type($file){
      $path_chunks = explode("/", $file);
      $thefile = $path_chunks[count($path_chunks) - 1];
      $dotpos = strrpos($thefile, ".");
      return strtolower(substr($thefile, $dotpos + 1));
  }
  $path = "files/";
  $file_types = array('', 'txt', 'html');
  $p = opendir($path);
      while (false !== ($filename = readdir($p))) {
          $files[] = $filename;
      }
  sort($files);
      foreach ($files as $file) {
          $extension = file_type($file);
          if($file != '.' && $file != '..' && array_search($extension, $file_types)){
              $file_count++;



?>

<h2> <?=$file?></h2>
(
<a href="<?=$path.$file?>" target="_blank">View</a> |
<a href="">Edit</a> |
<a href="?file=<?=urlencode($path.$file)?>">Delete</a> |
<a href="">Upload</a>)
<br/>

<?php @unlink(urldecode($_GET[file]));
header('Location: ' . $_SERVER['PHP_SELF']);?>

<?
          }
      }
?>


can anyone shed light on that for me, i am struggling and google and php.net are turning up nothing useful

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.