soddengecko Posted January 17, 2007 Share Posted January 17, 2007 Hi allI 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 havename_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? Quote Link to comment https://forums.phpfreaks.com/topic/34544-flat-file-createeditdelete/ Share on other sites More sharing options...
trq Posted January 17, 2007 Share Posted January 17, 2007 To add an edit feature you would simply read the file into a textarea, edit the data within the textarea, then save the new (edited) version over the old file.To delete, use [url=http://php.net/unlink]unlink[/url]. Quote Link to comment https://forums.phpfreaks.com/topic/34544-flat-file-createeditdelete/#findComment-162718 Share on other sites More sharing options...
soddengecko Posted January 17, 2007 Author Share Posted January 17, 2007 i can use the edit and unlink function if i was using a form submition, but i am using plain hypertext links and was wondering what the code for that would be? Quote Link to comment https://forums.phpfreaks.com/topic/34544-flat-file-createeditdelete/#findComment-162724 Share on other sites More sharing options...
taith Posted January 17, 2007 Share Posted January 17, 2007 [code]<a href="?file=<?=urlencode($filename)?>">Delete</a>[/code][code]unlink(urldecode($_GET[file]));[/code] Quote Link to comment https://forums.phpfreaks.com/topic/34544-flat-file-createeditdelete/#findComment-162740 Share on other sites More sharing options...
soddengecko Posted January 17, 2007 Author Share Posted January 17, 2007 excellent, i shall try that as soon as i get home this evening Quote Link to comment https://forums.phpfreaks.com/topic/34544-flat-file-createeditdelete/#findComment-162831 Share on other sites More sharing options...
soddengecko Posted January 17, 2007 Author Share Posted January 17, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/34544-flat-file-createeditdelete/#findComment-163098 Share on other sites More sharing options...
johnwayne77 Posted January 17, 2007 Share Posted January 17, 2007 try to redirect to a cloned page which will be a refresh copy of the control panel with the desired item not showing up Quote Link to comment https://forums.phpfreaks.com/topic/34544-flat-file-createeditdelete/#findComment-163214 Share on other sites More sharing options...
soddengecko Posted January 17, 2007 Author Share Posted January 17, 2007 Same problem unfortunately. damn good idea though. my code obviously has to be wrong there. Quote Link to comment https://forums.phpfreaks.com/topic/34544-flat-file-createeditdelete/#findComment-163241 Share on other sites More sharing options...
karthikeyan_coder Posted January 17, 2007 Share Posted January 17, 2007 BEST flatfile framwork...http://lukeplant.me.uk/resources/flatfile/it is having inbuilt manual...i got it after a 30 mins research... Quote Link to comment https://forums.phpfreaks.com/topic/34544-flat-file-createeditdelete/#findComment-163245 Share on other sites More sharing options...
soddengecko Posted January 17, 2007 Author Share Posted January 17, 2007 i came across that, but i found no use for the info. it did not help me Quote Link to comment https://forums.phpfreaks.com/topic/34544-flat-file-createeditdelete/#findComment-163250 Share on other sites More sharing options...
soddengecko Posted January 18, 2007 Author Share Posted January 18, 2007 just to let you all know, i now have this working. i used a redirect to another page and all is fine now.thanks for all the help and info Quote Link to comment https://forums.phpfreaks.com/topic/34544-flat-file-createeditdelete/#findComment-163552 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.