Tech Support Guy banner
  • Please post in our Community Feedback thread for help with the new forum software! If you are having trouble logging in, please Contact Us for assistance.
Status
Not open for further replies.
1 - 6 of 6 Posts

·
Registered
Joined
·
10 Posts
Discussion Starter · #1 ·
Hello,

I currently use a flat file (text file) database to manage data for a website that I run. The data is constantly added to and removed from. The problem is that although I am perfectly fine with modifying and reuploading the file, there are others that need to be able to modify the file, and reupload it, who aren't necessarily computer-savvy.

Basically, I am wondering if there is any way I can put up some sort of java plugin, or other script or something that would allow an authenticated user to modify the contents of a text file and save the changes. It doesn't need to be anything really elaborate, just a simple in-browser text editor that I can put on my own website.

Thanks in advance,

-Roshan
 

·
Registered
Joined
·
33 Posts
Php script i knocked up for you, its not very neat but well for 5 minutes work, what do you expect lol. All you need to change in the code is the name of the text file, i've indicated where this needs to be changed. Other than that simply paste the code into a file, and save this file as "edit.php", upload into the same directory as your text file, and point to the edit page and you should be good to go.

Paste into a file named 'edit.php'
PHP:
<?

$filecontents = $_POST['filecontents'];

if (!empty($filecontents)){

$file = "base.txt";
$fh = fopen($file, 'w') or die("can't open file");
fwrite($fh, $filecontents);
fclose($fh);

print("File Saved

[URL]Reload Page[/URL]");

} else {

$fp = fopen("base.txt", "r"); //replace base.txt with the name of your file

	while(!feof($fp)) {
		$data .= fgets($fp, 4096);
	}

fclose($fp);

print('

');

print("$data");

print('

');
}
 

·
Registered
Joined
·
10 Posts
Discussion Starter · #4 ·
Wow Howelly, thanks a bunch. That's exactly what I wanted, and I managed to get it to work. Now say I want to put this file in a separate directory than the text file that I'm editing, which would allow me to authenticate that directory, to write to a lower level directory would I just make it ../base.txt?
 

·
Registered
Joined
·
33 Posts
yeah was going to mention something in the original post incase you wanted it in a seperate directory. But yeah just change the path to where it is on the webserver.

If you had

root/scripts/edit.php
root/data/base.txt

the path would obviously be: '../data/base.txt'
 
1 - 6 of 6 Posts
Status
Not open for further replies.
Top