mrbhb Posted December 7, 2013 Share Posted December 7, 2013 (edited) 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. Now we can click to open 1 file such as “extensions.conf” to read, write and save it by button submit (update) Edited December 7, 2013 by mrbhb Quote Link to comment https://forums.phpfreaks.com/topic/284605-how-to-open-edit-file-in-list-content-of-directory/ Share on other sites More sharing options...
jcbones Posted December 7, 2013 Share Posted December 7, 2013 We don't "fix" your code, we offer solutions for YOU to fix your code.You need to look at the file_put_contents(). Quote Link to comment https://forums.phpfreaks.com/topic/284605-how-to-open-edit-file-in-list-content-of-directory/#findComment-1461573 Share on other sites More sharing options...
mrbhb Posted December 7, 2013 Author Share Posted December 7, 2013 Thank very much, I need some advice or answer. Quote Link to comment https://forums.phpfreaks.com/topic/284605-how-to-open-edit-file-in-list-content-of-directory/#findComment-1461594 Share on other sites More sharing options...
mrbhb Posted December 8, 2013 Author Share Posted December 8, 2013 here is my code, I need some help. plz <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <style type="text/css"> table { width: 100%; padding: 5px 5px 0px 5px; text-decoration:none; } a { text-decoration:none; } h3 { padding: 5px 0px 5px 0px; color:#000; } tr { height: 20px; } </style> </head> <body> <!--code show file cua thu muc--> <?php echo "<h3>LIST FILE OF FOLDER</h3>"; // directory $dir = ""; // Opens directory $myDirectory=opendir("."); // Gets each entry while($entryName=readdir($myDirectory)) { $dirArray[]=$entryName; } // Finds extensions of files function findexts ($filename) { $filename=strtolower($filename);//chuyen sang chu thuong $exts=split("[/\\.]", $filename);//cat chuoi $n=count($exts)-1; $exts=$exts[$n]; return $exts; } // Closes directory closedir($myDirectory); // Counts elements in array $indexCount=count($dirArray); // Sorts files sort($dirArray); // Print list content directory print("<TABLE border=1 cellpadding=5 cellspacing=0 class=whitelinks>\n"); print("<TR><TH>Name</TH><th>Type</th><th>Size</th><th>Date Modified</th></TR>\n"); // Loops through the array of files for($index=0; $index < $indexCount; $index++) { if (substr("$dirArray[$index]", 0, 1) != ".") { //File name $name=$dirArray[$index]; $namehref=$dirArray[$index]; // Gets File Extensions $extn=findexts($dirArray[$index]); // File type switch ($extn) { case "png": $extn="PNG Image"; break; case "jpg": $extn="JPEG Image"; break; case "bmp": $extn="BITMAP Image"; break; case "gif": $extn="GIF Image"; break; case "ico": $extn="Windows Icon"; break; case "txt": $extn="Text File"; break; case "log": $extn="Log File"; break; case "htm": $extn="HTML File"; break; case "php": $extn="PHP Script"; break; case "js": $extn="Javascript"; break; case "css": $extn="Stylesheet"; break; case "pdf": $extn="PDF Document"; break; case "zip": $extn="ZIP Archive"; break; case "docx": $extn="Microsoft Word Document"; break; case "mp3": $extn="MP# Format Sound"; break; default: $extn=strtoupper($extn)." File"; break; } // Gets file size $size=number_format(filesize($dirArray[$index]))." "."KB"; // Gets Date Modified Data $modtime=date("M j Y g:i A", filemtime($dirArray[$index])); $timekey=date("YmdHis", filemtime($dirArray[$index])); print(" <tr> <td><a href='./$namehref'>$name</a></td> <td><a href='./$namehref'>$extn</a></td> <td><a href='./$namehref'>$size</a></td> <td sorttable_customkey='$timekey'><a href='./$namehref'>$modtime</a></td> </tr>"); /*print("<TR><TD><a href=\"$dirArray[$index]\">$dirArray[$index]</a></td>"); print("<td>"); print(findexts($dirArray[$index])); //print(filetype($dirArray[$index])); print("</td>"); print("<td>"); print(filesize($dirArray[$index])); print("</td>"); print("<td>"); print($modtime); print("</td>"); print("</TR>\n");*/ } } print("</TABLE>\n"); ?> <!--code doc sua va luu 1 file bat ky--> <br /> <h3>OPEN, EDIT AND SAVE ANY FILE IN LIST FILE OF FOLDER</h3> <br /> <form name="read_form" method="post" action=""> <textarea name="read_file" cols="110" rows="35" wrap="off"> </textarea> <br /> <input type="submit" name="update" value="UPDATE" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/284605-how-to-open-edit-file-in-list-content-of-directory/#findComment-1461697 Share on other sites More sharing options...
jcbones Posted December 9, 2013 Share Posted December 9, 2013 What to you need help with? Quote Link to comment https://forums.phpfreaks.com/topic/284605-how-to-open-edit-file-in-list-content-of-directory/#findComment-1461885 Share on other sites More sharing options...
mrbhb Posted December 17, 2013 Author Share Posted December 17, 2013 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. <?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 Quote Link to comment https://forums.phpfreaks.com/topic/284605-how-to-open-edit-file-in-list-content-of-directory/#findComment-1462560 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.