newbtophp Posted May 29, 2009 Share Posted May 29, 2009 Im trying to code a snippet which will display a php file, which can then be edited within another webpage. I've completed it accept, it has a few flaws, once you edit the code the page exploads and messes up, and when you come back to the code inbetween each code I see \ dashes. Heres my code.php (which edits text.php): <? if($_POST['Submit']){ $open = fopen("text.php","w+"); $text = $_POST['update']; fwrite($open, $text); fclose($open); echo "File updated.<br />"; echo "File:<br />"; $file = file("text.php"); foreach($file as $text) { echo $text."<br />"; } echo "<p><a href=\"./text.php\" target=_blank>click here to view the updated file</a></p>"; }else{ $file = file("text.php"); echo "<form action=\"".$PHP_SELF."\" method=\"post\">"; echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">"; foreach($file as $text) { echo $text; } echo "</textarea>"; echo "<BR><input name=\"Submit\" type=\"submit\" value=\"Update\" />\n </form>"; } ?> Is their a way to continue what im doing but remove the demo of the file edited (so the page dont expload), and remove it from showing dashes. Heres the live demo (for you to test): http://www.encrypt.hostxcel.co.uk/admin/code.php Thanks Quote Link to comment https://forums.phpfreaks.com/topic/160152-solved-remotely-editing-a-php-file-within-another-php-file/ Share on other sites More sharing options...
DarkSuperHero Posted May 29, 2009 Share Posted May 29, 2009 your probably have to URL encode your $_POST['update'] text and then go ahead and unencode it when you write it to the php file.... <?php if($_POST['Submit']){ $open = fopen("text.php","w+"); $text = $_POST['update']; fwrite($open, urldecode($text)); fclose($open); echo "File updated.<br />"; echo "File:<br />"; $file = file("text.php"); foreach($file as $text) { echo $text."<br />"; } echo "<p><a href=\"./text.php\" target=_blank>click here to view the updated file</a></p>"; }else{ $file = file("text.php"); echo "<form action=\"".$PHP_SELF."\" method=\"post\">"; echo "<textarea Name=\"update\" id=\"phpCode\"cols=\"50\" rows=\"10\">"; foreach($file as $text) { echo $text; } echo "</textarea>"; echo "<BR><input name=\"Submit\" type=\"submit\" value=\"Update\" onClick=\"document.getElementById('phpCode').value = escape(document.getElementById('phpCode').value)\"/>\n </form>"; } ?> Try That... //Modified to edit source code... Quote Link to comment https://forums.phpfreaks.com/topic/160152-solved-remotely-editing-a-php-file-within-another-php-file/#findComment-844982 Share on other sites More sharing options...
newbtophp Posted May 29, 2009 Author Share Posted May 29, 2009 Its better, the code doesnt show any dashes anymore so thats great: http://www.encrypt.hostxcel.co.uk/admin/code.php But the preview still shows, on the main page even though theirs a link to preview in a new tab. Any idea on how to remove the preview on the main page? :-\ Quote Link to comment https://forums.phpfreaks.com/topic/160152-solved-remotely-editing-a-php-file-within-another-php-file/#findComment-844992 Share on other sites More sharing options...
DarkSuperHero Posted May 29, 2009 Share Posted May 29, 2009 <?php if($_POST['Submit']){ $open = fopen("text.php","w+"); $text = $_POST['update']; fwrite($open, urldecode($text)); fclose($open); echo "File updated.<br />"; /* This Section displays the file's contents... look into file() on php.net for more details on how it works... echo "File:<br />"; $file = file("text.php"); foreach($file as $text) { echo $text."<br />"; } */ echo "<p><a href=\"./text.php\" target=_blank>click here to view the updated file</a></p>"; }else{ $file = file("text.php"); echo "<form action=\"".$PHP_SELF."\" method=\"post\">"; echo "<textarea Name=\"update\" id=\"phpCode\"cols=\"50\" rows=\"10\">"; foreach($file as $text) { echo $text; } echo "</textarea>"; echo "<BR><input name=\"Submit\" type=\"submit\" value=\"Update\" onClick=\"document.getElementById('phpCode').value = escape(document.getElementById('phpCode').value)\"/>\n </form>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/160152-solved-remotely-editing-a-php-file-within-another-php-file/#findComment-844996 Share on other sites More sharing options...
newbtophp Posted May 29, 2009 Author Share Posted May 29, 2009 Thanks DarkSuperHero. Topic Solved Quote Link to comment https://forums.phpfreaks.com/topic/160152-solved-remotely-editing-a-php-file-within-another-php-file/#findComment-845002 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.