Jump to content

Recommended Posts

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

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...

Its better, the code doesnt show any dashes anymore :D 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?  :-\

<?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>";
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.