Jump to content

[SOLVED] Insite PHP editor...


Steve19Ohio

Recommended Posts

Ok. I'm trying to make a few pages of PHP that can open others that I select and bring the code up in a edit box that I can make and save my changes to them. That way I don't have to upload the changed files to my host everytime I want to fix or change something. Heres what I got so far...

 

 

First here are a few test PHP files to use

 

Test1.php

<? echo 'test 1' ?>

 

Test2.php

<? echo 'test 2' ?>

 

Test3.php

<? echo 'test 3' ?>

 

Now here is then Page that lest me select the PHP page I want to edit.

 

PHP_edit_index.php

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<body>
<form method="POST" action="php_edit_edit.php">
<!--webbot bot="SaveResults" U-File="fpweb:///_private/form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
<p><select size="1" name="sendfile">
<option>test1.php</option>
<option>test2.php</option>
<option>test3.php</option>
</select><input type="submit" value="Submit" name="B1"></p>
</form>
</body>
</html>

 

and here is the editor...

 

PHP_EDIT_edit

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>PHP Editor</title>
</head>
<body>
<form method="POST" action="php_edit_review.php">
<!--webbot bot="SaveResults" U-File="fpweb:///_private/form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
<p><textarea rows="17" name="S1" cols="114"><?php
$file = $_POST['sendfile'];
$handle = fopen($file, "rt");
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 8192);
echo $buffer;
}
fclose($handle);
}
?>
</textarea></p>
<p><input type="submit" value="Review" name="edited">      <input type="reset" value="Reset" name="B2"></p>
</form>
</body>
</html>

 

 

This is the Review Page

 

PHP_Edit_review.php

<?

$edited = $_POST['edited'];

echo $edited

?>

 

 

 

The Review page just brings up "Save" and not the code. Also I need to know how to save the file changed. Any help would be Great... Thanks...

 

 

I added all the files ziped so you can look at it. Thanks...

 

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

I don't see why you just don't use an editor that has FTP build in, so when you hit save it just saves it to your webhost.

 

Or are you trying to learn?

 

 

Well right now I'm in Iraq so I can't use a program on my computer cause I don't have internet. Plus I'm trying to learn PHP better. I'm new to it. So I'm just playing around seeing what I can do. I haven't fount any source for a PHP app like this so I don't know if there is one out there or not. Thanks for the reply though.

Link to comment
Share on other sites

to save file I'd look into file_put_contents() or fopen()/fwrite()/fclose() for a bit more options.

http://us3.php.net/file_put_contents

 

This looks good. Thanks for the info. It will take me an hour or two to review it. Thanks. What do you think about what I've done so far? What about Previewing the info? For some reason it isn't showin up like I think it should... Thanks again...

Link to comment
Share on other sites

Ok. I fount my 'Review' mistake. I named the submit button "edited" and not the form. But even when I fixed it now it displays nothing on the preview page. Here is the corrected code

 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>PHP Editor</title>
</head>
<body>
<form method="POST" action="php_edit_review.php">
<!--webbot bot="SaveResults" U-File="fpweb:///_private/form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
<p><textarea rows="17" name="edited" cols="114"><?php
$file = $_POST['sendfile'];
$handle = fopen($file, "rt");
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 8192);
echo $buffer;
}
fclose($handle);
}
?>
</textarea></p>
<p><input type="submit" value="Review" name="b1">      <input type="reset" value="Reset" name="b2"></p>
</form>
</body>
</html>

Link to comment
Share on other sites

to improve readibility you might consider replacing...

 

<?php
$handle = fopen($file, "rt");
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 8192);
echo $buffer;
}
fclose($handle);
}
?>

 

with

 

<?php
echo file_get_contents($file);
?>

 

your current problem is you're using fopen() with rt instead of r+.

Link to comment
Share on other sites

to improve readibility you might consider replacing...

 

<?php
$handle = fopen($file, "rt");
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 8192);
echo $buffer;
}
fclose($handle);
}
?>

 

with

 

<?php
echo file_get_contents($file);
?>

 

your current problem is you're using fopen() with rt instead of r+.

 

 

 

Thanks for that... Its a lot easier to read now... I think I'm going to just skip the who Review and post to self and save the file. I was reading what you recommend. I think I can use

 

<?
file_put_contents ( ... ) 
?>

 

What do you think?

Link to comment
Share on other sites

Ok. I got it to save the file. But how do I keep passing the file name thru the different pages? Or Should I use if statements? Not really sure how to use those. Any help would be great. Here is all the new stuff I got...

 

 

php_edit_index.php

 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<body>
<form method="POST" action="php_edit_edit.php">
<!--webbot bot="SaveResults" U-File="fpweb:///_private/form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
<p><select size="1" name="targetfile">
<option>test1.php</option>
<option>test2.php</option>
<option>test3.php</option>
<option>../test4.php</option>
</select><input type="submit" value="Submit" name="B1"></p>
</form>
</body>
</html>

 

 

php_edit_edit.php

 

<?
$file = $_POST['targetfile'];
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>PHP Editor</title>
</head>
<body>
<form method="POST" action="php_edit_save.php"><p><textarea rows="17" name="edited" cols="114">
<?
echo file_get_contents($file);
?>
</textarea></p><name="<? $file ?>">
<p><input type="submit" value="Save File" name="B1">                  
                              
<input type="reset" value="Undo ALL Changes" name="B2"></p>
</form>
</body>
</html>

 

 

php_edit_save.php

 

<?
$file = 'test1.php';
$edited = $_POST[edited];
file_put_contents($file, $edited);
?>
<p><font size="5">Changes to <?echo $file ?> were saved</font></p>
<p> </p>
<p><font size="5">Return to </font><a href="php_edit_index.php"><font size="5">
PHP Editor</font></a></p>

 

See how i had to place the file name in the Save PHP file. How do I Pass it along to the next page? Also when I save a lot of code. It places ramdom "/" everywhere in it. Whats that about? Thanks...

Link to comment
Share on other sites

Well as for passing the file name, you could put it into a hidden value in the form to be passed along when the modifications are made, put in the get request of the action="" of the form, eg. action="modify.php?edit=myotherpage.php", or you could save the file name in a session.

 

As for the random backslashes, it's likely that you have magic_quotes_gpc enabled in your php.ini. Either disable that in the current directory in .htaccess (with apache), disable it in your php.ini, or use stripslashes() on the input before saving. More info: http://us.php.net/magic_quotes

Link to comment
Share on other sites

Well as for passing the file name, you could put it into a hidden value in the form to be passed along when the modifications are made, put in the get request of the action="" of the form, eg. action="modify.php?edit=myotherpage.php", or you could save the file name in a session.

 

As for the random backslashes, it's likely that you have magic_quotes_gpc enabled in your php.ini. Either disable that in the current directory in .htaccess (with apache), disable it in your php.ini, or use stripslashes() on the input before saving. More info: http://us.php.net/magic_quotes

 

I just read a turtorial about sessions. I'm going to save it so I can take it home to read and try. I'll disable the magic quotes too. I thought that might be the reason for it. Thanks for the Reply... Your always helpful...

Link to comment
Share on other sites

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.