Jump to content

file editor


Guest fmx22
 Share

Recommended Posts

Guest fmx22

ok welll i am trying to make a system where i can have a user open a fille that has been previously uploaded by us(.txt file), and when they go to a certain page, i want the file to open in a textarea so they can edit it, then save it. How can i go about doing this? Can someone show me how? Thanks

Link to comment
Share on other sites

ok, here is an idea:

<?php $filename = "yourfile.txt";$fd = fopen ($filename , "r"); $fstring = fread ($fd , filesize ($filename)); fclose($fd); ?> <html>...<form action="write.php" method="POST"><textarea name="file" cols="10" rows="30"><?php echo $fstring; ?></textarea></form>...</html>

then write.php:

<?php$filename = "yourfile.txt";$fd = fopen($filename , "w");$fout = fwrite($fd , $_POST['file'] );fclose($fd);?>

then you can add a function for redirecting.LG

Link to comment
Share on other sites

You'll probably want them to either click on a filename or select a file from a dropdown. Either way, the page that lets them edit the file needs to get the filename from somewhere. You can either get the list of files and spit them out in a list of links, or in a dropdown.The page that gets the filename needs to open the file and write the contents inside the text box. That page also needs to make sure to put the filename in a hidden input field to send to the next page:

<?phpecho "<input type=\"hidden\" name=\"filename\" value=\"" . htmlentities($filename) . "\">";echo "<textarea name=\"editfile\">" . file_get_contents($filename) . "</textarea>";?>

When the user submits that page, you need to get the edited file contents and just open the same file and write the new contents into it. Here's a reference and example on how to write data to a file:http://www.php.net/manual/en/function.fwrite.php

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...