DJTim666 Posted October 2, 2007 Share Posted October 2, 2007 Is it possible to get the contents of a file; display the contents in a textbox; and edit the contents of that file. Then click a button and change the contents to the new updated file. The reason I want to know this is because I have programmers on my site and I don't want them to have access to the FTP or cPanel. They will jus enter the name of the file, click submit, be able to edt and replace that file. All without FTP or cPanel . I hope this is possible. -- DJ Quote Link to comment https://forums.phpfreaks.com/topic/71473-getting-the-contents-of-a-file/ Share on other sites More sharing options...
teng84 Posted October 2, 2007 Share Posted October 2, 2007 http://www.php.net/manual/en/function.fread.php http://www.php.net/manual/en/function.fwrite.php :-\ Quote Link to comment https://forums.phpfreaks.com/topic/71473-getting-the-contents-of-a-file/#findComment-359799 Share on other sites More sharing options...
sKunKbad Posted October 2, 2007 Share Posted October 2, 2007 I came up with this script based on the links you provided. I'm sure it is a security nightmare waiting to happen, but it shows that this can be done easily (since I still consider myself a php noob). <html> <head> <style type="text/css"> #editbox { width:500px; height:200px; } </style> </head> <body> <?php if ($_GET['editbox'] != ""){ $filename = 'fread_text.txt'; $somecontent = $_GET['editbox']; if (is_writable($filename)) { if (!$handle = fopen($filename, 'w')) { echo "Cannot open file ($filename)"; exit; } if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote ($somecontent) to file ($filename)"; fclose($handle); } else { echo "The file $filename is not writable"; } }else{ $filename = "fread_text.txt"; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); echo "<form action='fread.php' method='get'> <input type='text' name='editbox' id='editbox' value='$contents'></input> <input type='submit' value='Submit' /> </form>"; fclose($handle); } ?> </body> </html> My fread_text.txt file just had some numbers in it like "293842938" to start with. Quote Link to comment https://forums.phpfreaks.com/topic/71473-getting-the-contents-of-a-file/#findComment-359819 Share on other sites More sharing options...
jagat21 Posted October 2, 2007 Share Posted October 2, 2007 this also might help u ............. http://in.php.net/file_get_contents Quote Link to comment https://forums.phpfreaks.com/topic/71473-getting-the-contents-of-a-file/#findComment-359848 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.