How to Open & Edit file in List Content of Directory.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bhb
Forum Newbie
Posts: 5
Joined: Sat Dec 07, 2013 7:31 am

How to Open & Edit file in List Content of Directory.

Post by bhb »

Hello Everyone, I’m having a page php have function list content of directory in computer such as c:/folder after that I can open, write and save any file I want in list file. Now I have complete to list content of directory, now I want to click any file in list file of derectory to open in a textarea under list content of drictory to view and edit file, then I have a button submit to save it. I don’t know how to do it so please fix my code I give under introduce me some example demo code or document to reference. Please help me. Thank very much.
Here is my code:
https://www.mediafire.com/?19123qkmgmf7toj
Example picture about page equivalent and similar:
In this picture it have list file.
Image
Now we can click to open 1 file such as “extensions.conf” to read, write and save it by button submit (update)
Image
bhb
Forum Newbie
Posts: 5
Joined: Sat Dec 07, 2013 7:31 am

Re: How to Open & Edit file in List Content of Directory.

Post by bhb »

Who known ? Please give me some answer?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How to Open & Edit file in List Content of Directory.

Post by Celauran »

I'm not going to download some random mediafire link, and I doubt anyone here will either. Post the relevant parts of your code and we'll see what we can do.
bhb
Forum Newbie
Posts: 5
Joined: Sat Dec 07, 2013 7:31 am

Re: How to Open & Edit file in List Content of Directory.

Post by bhb »

I still don't know how to when I click to file name in list content of directory, it content have show in textarea, what event click to to it ? I have read a example simple below but it open and save file have direct directory.

Code: Select all

<?php

$filename = isset($_GET['file']) ? $_GET['file'] : '';
$directory = ("c:/folder/file.php"); // Restrict to this directory...

$fn = $directory . $filename;

if (isset($_POST['content']))
{
    $content = stripslashes($_POST['content']);
    $fp = fopen($fn,"w") or die ("Error opening file in write mode!");
    fputs($fp,$content);
    fclose($fp) or die ("Error closing file!");
}

?>

<form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post">
    <textarea rows="25" cols="100" name="content"><?php readfile($fn); ?></textarea>
    <hr />
    <input type="submit" value="Save">
</form>
Here is my https://www.mediafire.com/?l3go25zl88359zu
stanliwise
Forum Newbie
Posts: 5
Joined: Mon Dec 23, 2013 5:00 am

Re: How to Open & Edit file in List Content of Directory.

Post by stanliwise »

I think you should read more on php file manger function e.g scandir(); or DirectoryIterator() function.
Scandir give an array list of files in folder.
While the latter do the same and even more.
After read it.
Just try to loop the function in an html <select><option></option></select> tags.
I am waiting for your reply.
Post Reply