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


Use PHP to modify a text file

Reply
  #1 (permalink)  
Old 05-23-04, 01:13 PM
bxcheats bxcheats is offline
Newbie Coder
 
Join Date: May 2004
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
Angry Use PHP to modify a text file

I have a flash animation I made that loads its information from a text file. The purpose is to display news on my site. I wish to be able to make a PHP form that makes a new "Post" to the text file.

Everything is located at http://bxcheats.togetherhost.com/
Reply With Quote
  #2 (permalink)  
Old 05-23-04, 01:34 PM
Lost Lost is offline
Wannabe Coder
 
Join Date: Mar 2004
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
First you need to make sure the text file is CHMOD'ed to permission 777 to allow for reading, writing, and executing. Then write a PHP script such as this:

<?php
if($_POST[author]&&$_POST[message]&&$_POST[title])
{
$time = date("r");
$filename = "http://www.somedomain.com/textfile.txt";
$newspost = "Author: $_POST[author]\nDate: $time\nTitle: $_POST[title]\nMessage: $_POST[message]\n\n";
if (is_writable($filename))
{
if (!$handle = fopen($filename, 'a'))
{
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, $newspost) === FALSE)
{
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote <i>\n$newspost\n</i> to file <i>$filename</i>";
fclose($handle);
}
else
{
echo "The file $filename is not writable";
}
}
else
{
echo "<form action=\"$_SERVER[PHP_SELF]\" method=\"post\">
Author: <input type=\"text\" name=\"author\"><br>
Title: <input type=\"text\" name=\"title\"><br>
Message: <textarea name=\"message\"></textarea><br><br>
<input type=\"submit\" value=\"Post News\">";
}
?>

You may have to test this a few times as I am not sure if it works or not.
Reply With Quote
  #3 (permalink)  
Old 05-23-04, 02:46 PM
bxcheats bxcheats is offline
Newbie Coder
 
Join Date: May 2004
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
Angry

What about the image?

And I change the permissions to 777 and I still get "The file http://bxcheats.togetherhost.com/news.txt is not writable".

Last edited by bxcheats; 05-23-04 at 02:55 PM.
Reply With Quote
  #4 (permalink)  
Old 05-23-04, 03:28 PM
bxcheats bxcheats is offline
Newbie Coder
 
Join Date: May 2004
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
Question Here is a more detialed description of what I need/want

I have a flash animation I made that loads its information from a text file. The purpose is to display news on my site. I have the flash file and the location of the text file below. I have set CHMOD value to 777 on the text file.

The flash file has a title and message text areas, I want a PHP script that posts an image I specify off my server, the author name, the time then the message. I want to keep the existing news and put the new news I post with the PHP form above the old news.

Everything is located at http://bxcheats.togetherhost.com/ and the flash file is on the homepage.
Reply With Quote
  #5 (permalink)  
Old 05-23-04, 07:31 PM
Lost Lost is offline
Wannabe Coder
 
Join Date: Mar 2004
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by bxcheats
What about the image?

And I change the permissions to 777 and I still get "The file http://bxcheats.togetherhost.com/news.txt is not writable".
You said nothing about an image...and that is the best I can do...I dont feel like writing a long script without some sort of payment.
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 04:03 AM
PHP write to text file veeco Script Requests 2 02-10-10 02:48 PM
Text File to PHP mdurrant PHP 2 04-26-04 08:31 PM
How to write a php script to load a text file into a table automatically? xmxpcom PHP 2 02-12-04 08:37 AM
picking random entries with a filter... Double selection problem dsumpter PHP 7 11-16-03 07:19 PM


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