Current location: Hot Scripts Forums » Programming Languages » PHP » One PHP file to edit another....


One PHP file to edit another....

Reply
  #1 (permalink)  
Old 07-16-03, 01:42 PM
drgn91 drgn91 is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
One PHP file to edit another....

what i need is for one PHP file, e.g an admin CP, to edit another php or html file.

for example, replace template.php with
Code:
code blah blah djbsipb

input box 1

more code blah

input box 2

blah blah
by filling in the in the input boxes on a php page.
any help would be appreciated
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-17-03, 07:08 AM
Jerome Jerome is offline
Wannabe Coder
 
Join Date: Jun 2003
Location: On Earth
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
i think you can use this php command ...

include ("admin.php");

//the admin.php is pointing to the file you want as a base.
__________________
Support me by clicking ads
@ http://atomise.blogspot.com
CHEERS
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-17-03, 09:39 AM
antoshka antoshka is offline
New Member
 
Join Date: Jul 2003
Location: USA
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
you want to create a script that will allow people to edit PHP files in their browser window?

there's 2 parts to it...

1. create a script that will load the php file and allow user to edit it.
PHP Code:

<?php

$file 
"/home/dir/file.php";
$fs fopen$file"a+" ) or die("error when opening the file");

while (!
feof($fs)) {
   
$contents .= fgets($fs1024);
}

fclose($fs);
?>

<html>
<form action="save.php" method="post">
<input type=hidden name="file" value="<?php echo $file?>">
<textarea name="contents"><?php echo htmlspecialchars($contents); ?></textarea>
</form>
</html>
2. create a script that will save the file once user done editing it.
PHP Code:

<?php

$fs 
fopen$_POST["file"], "a+" ) or die("error when opening the file");
fwrite($fs$_POST["contents"]);
fclose();
?>
this code might have bugs... it's very basic too.
__________________
RouTHost.com
PHP MySQL Perl SSI e-commerce
plans start at $3.95!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-17-03, 11:14 AM
drgn91 drgn91 is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
so what parts do i need to edit?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 07-17-03, 12:30 PM
antoshka antoshka is offline
New Member
 
Join Date: Jul 2003
Location: USA
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
if you use the code i posted above, it should work. however, you might want to add some error checking in there. you could check if the file can be written (sometimes you can open it for writing, but you can't write in it), if user's input is valid, etc.

also the first script has a hardcoded parameter $file. you probably want to pass that parameter to the script from the outside somehow.
__________________
RouTHost.com
PHP MySQL Perl SSI e-commerce
plans start at $3.95!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 07-17-03, 12:43 PM
drgn91 drgn91 is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
1. what would happen if the file was already there? would it overwrite it?

2. how would i make it so it had lots of uneditable code, then the content of an input box (e.g a color), then more code, then another input and so on....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 07-18-03, 02:29 PM
drgn91 drgn91 is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
anyone?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 07-18-03, 03:35 PM
ChristGuy ChristGuy is offline
Operations Support Develo
 
Join Date: Jun 2003
Location: Rivonia, South Africa
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
Greetingz...

1. FOpen("...", "a+") // Appends to the file

2. You'd need to Include() the edited file, that has the values saved as variables...

Then Just <?php echo $VariableName ?>
__________________
Till We Meet Again...
Clifford W. Hansen
Aspivia (Pty) Ltd

"We Have Seen Strange Things Today!" Luke 5:26
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 07-19-03, 08:08 AM
drgn91 drgn91 is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 07-21-03, 12:21 PM
drgn91 drgn91 is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
http://www.novacurity.com/cncburnout/XWeb/cp.php

look what happens.... both file.php and cp.php are CHMODed to 0777.
here is the code of cp.php:

Code:
<html>

<head>
  <title></title>
</head>

<body>

<?php

$file = "/home/novacuri/public_html/cncburnout/XWeb/file.php";

$fs = fopen( $file, "a+" ) or die("error when opening the file");


while (!feof($fs)) {

   $contents .= fgets($fs, 1024);

}


fclose($fs);

?>




<form action="save.php" method="post">

<input type=hidden name="file" value="<?php echo $file; ?>">

<textarea name="contents"><?php echo htmlspecialchars($contents); ?></textarea>

</form>


<?php

$fs = fopen( $_POST["file"], "a+" ) or die("error when opening the file");

fwrite($fs, $_POST["contents"]);

fclose();

?>


</body>

</html>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP code to edit a text file mdhall Script Requests 12 12-23-10 05:03 AM
one-page form/catalog in php, data fed in with .csv file? domaky PHP 2 10-25-03 10:32 AM
Problem with Read from file by PHP Pothik Script Requests 5 09-15-03 09:42 AM
PHP - Dir listing and write to file NickyWhicko PHP 4 08-24-03 03:42 AM
PHP and TXT file Vyrus PHP 10 07-13-03 12:05 PM


All times are GMT -5. The time now is 12:45 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.