Current location: Hot Scripts Forums » General Community » Script Requests » PHP code to edit a text file


PHP code to edit a text file

Reply
  #11 (permalink)  
Old 12-09-10, 02:27 AM
phpaid's Avatar
phpaid phpaid is offline
Newbie Coder
 
Join Date: Nov 2010
Location: Northwest USA
Posts: 38
Thanks: 0
Thanked 4 Times in 4 Posts
Quote:
Originally Posted by pastel.pro View Post
Thanks for your script.
I've simplified a little more :
PHP Code:

<?php

$fn 
"test.txt";

if (isset(
$_POST['content']))
{
    
$content stripslashes($_POST['content']);
    
$fp fopen($fn,"w") or die ("Error opening file in write mode!");
    
fputs($fp,$content);
    
fclose($fp) or die ("Error closing file!");
}
?>

<form action="<?php echo $_SERVER["PHP_SELF"?>" method="post">
    <textarea rows="25" cols="40" name="content"><?php readfile($fn); ?></textarea>
    <input type="submit" value="Sauver"> 
</form>
Please note that a file like this is extremely dangerous and should not be used on originals. Use at your own risk.
__________________
PHP AID - PHP Scripts, News, PHP Downloads, All Free
Reply With Quote
  #12 (permalink)  
Old 12-22-10, 03:26 PM
lauris3722 lauris3722 is offline
New Member
 
Join Date: Dec 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by pastel.pro View Post
Thanks for your script.
I've simplified a little more :
PHP Code:

<?php

$fn 
"test.txt";

if (isset(
$_POST['content']))
{
    
$content stripslashes($_POST['content']);
    
$fp fopen($fn,"w") or die ("Error opening file in write mode!");
    
fputs($fp,$content);
    
fclose($fp) or die ("Error closing file!");
}
?>

<form action="<?php echo $_SERVER["PHP_SELF"?>" method="post">
    <textarea rows="25" cols="40" name="content"><?php readfile($fn); ?></textarea>
    <input type="submit" value="Sauver"> 
</form>
I modified it a bit and for some reason its not working..

PHP Code:

<form action="edit.php" method="get">

Name: <input type="text" name="fname" />
<
input type="submit" />
</
form
PHP Code:

<?php

$fn 
$_GET["fname"];

if (isset(
$_POST['content']))
{
    
$content stripslashes($_POST['content']);
    
$fp fopen($fn,"c+") or die ("Error opening file in write mode!");
    
fputs($fp,$content);
    
fclose($fp) or die ("Error closing file!");
}
?>
<p>
<form action="<?php echo $_SERVER["PHP_SELF"?>" method="post">
    <textarea rows="30" cols="80" name="content"><?php readfile($fn); ?></textarea>
    <input type="submit" value="Sauver"> 
</form>
Getting "Error opening file in write mode!"
Reply With Quote
  #13 (permalink)  
Old 12-23-10, 04:03 AM
yelbom yelbom is offline
New Member
 
Join Date: Oct 2005
Location: North Carolina
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
This this php snippent to post & edit text file

Try this

PHP Code:

<?php

function make_content_file($filename,$content,$opentype="w"){
    
$fp_file fopen($filename$opentype);
    
fputs($fp_file$content);
    
fclose($fp_file);
}

$filename "tags.txt";

if(
$_POST){
 
$newcontents=$_POST[newcontents];
 
make_content_file($filename,$newcontents);
}

$filecontents file_get_contents($filename);

?>

<?php
if($_POST){
echo 
'<p><span style="font-weight: 700; background-color: #CCFFCC">You have successfully posted to your txt file!</span></p>
<a href="tags.txt">Download</a>'
;
}
?>

<form method="post">
<textarea name="newcontents" cols="70" rows="25"><?=$filecontents?></textarea>
<br>
<input type="submit" value="Save">  
</form>
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
protecting code in PHP ckb PHP 12 01-02-04 08:53 AM
Problem with Read from file by PHP Pothik Script Requests 5 09-15-03 08:42 AM
Writes to a text file gamextremer2003 JavaScript 4 09-11-03 09:43 AM
One PHP file to edit another.... drgn91 PHP 10 07-22-03 11:29 AM
edit php in Squirrelmail jrcortrightiii PHP 1 07-10-03 02:08 PM


All times are GMT -5. The time now is 11:55 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.