...

View Full Version : I need a php Class to Edit php files



Dooq
03-03-2008, 02:53 PM
I need a php class to edit one php file (english.php) through textarea.

I failed to find that kind of classes. can you help me please ?

I think any class to edit flat txt file are fine.

thanks :thumbsup:

_Aerospace_Eng_
03-03-2008, 05:49 PM
You don't need a class for this. Simple functions will allow you to do this. Here is a very basic example. You need to make it more secure as well as put it in a password protected area.

<?php
$contents = '';
if(isset($_POST['submit']) && $_POST['submit'] == 'Edit')
{
if($_POST['contents'] != '')
{
$contents = $_POST['contents'];
}
$newfp = fopen('english.php','w+');
fwrite($newfp,stripslashes($contents));
fclose($newfp);
}
$fp = file_get_contents('english.php');
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<textarea cols="40" rows="10" name="contents"><?php echo $fp; ?></textarea>
<input type="submit" name="submit" value="Edit" />
<?php echo ?>
</form>

Dooq
03-04-2008, 03:08 PM
You don't need a class for this. Simple functions will allow you to do this. Here is a very basic example. You need to make it more secure as well as put it in a password protected area.

<?php
$contents = '';
if(isset($_POST['submit']) && $_POST['submit'] == 'Edit')
{
if($_POST['contents'] != '')
{
$contents = $_POST['contents'];
}
$newfp = fopen('english.php','w+');
fwrite($newfp,stripslashes($contents));
fclose($newfp);
}
$fp = file_get_contents('english.php');
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<textarea cols="40" rows="10" name="contents"><?php echo $fp; ?></textarea>
<input type="submit" name="submit" value="Edit" />
<?php echo ?>
</form>

When I did this, I lost the php layout.

for example the below code :


<?php

echo 'foo';

print "test";


?>


will be saved as :


<?php\r\n\r\necho \\\'foo\\\';\r\n\r\nprint \\"test\\";\r\n\r\n\r\n?>


how can I solve this problem ?

Dooq
03-04-2008, 03:50 PM
problem solved



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum