Current location: Hot Scripts Forums » Programming Languages » PHP » Posting to TOP of a text file.


Posting to TOP of a text file.

Reply
  #1 (permalink)  
Old 02-13-05, 08:59 AM
Handle Handle is offline
New Member
 
Join Date: Feb 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Question Posting to TOP of a text file.

Hi.

Im trying to make a shout box that displays posts in a gd image that i plan to use in my sig on my forum.

The problem i am having is the php script posts to the bottom of the .txt file.
This means after 6 posts any new posts are not visible because they have dissappeared off the bottom of the image.

To fix this problem i need to either make the php post the posts to the top of the text file (while moving other posts down, not overwriting) or make the script that produces the image read only the last 6 posts from the .txt file.
I dont know how to do either.

Any help would be great.

This is the script that posts the 'shouts' to the txt file.
PHP Code:

<?php 


$filename 
"shouts.txt"


$shout trim(strip_tags(stripslashes$_POST['shout']))); 
$name trim(stripslashes(strip_tags($_POST['name']))); 


$fp fopen($filename,'a'); // 'a' will append or add to the file 

        
fwrite($fp"$name - $shout\n"); 
    } 
fclose($fp); 

?>
And this is the php that gets the text from the txt file and produces the image
PHP Code:

<?php 

// shout sig 
header("Content-type: image/png"); 
$file file('shouts.txt'); 


$im = @imagecreate(550120
   or die(
"Error! Could not create image stream.s"); 
$background_color imagecolorallocate($im000); 
$text_color imagecolorallocate($im02550); 
$i 1
$j 0
foreach (
$file as $line_num => $line) { 
    if(
$i <= count($file)-1
        
imagestring($im25$j,  substr($line0strlen($line)-1), $text_color); 
    else 
        
imagestring($im25$j,  $line$text_color); 
    
$j+=15
    
$i++; 

imagepng($im); 
imagedestroy($im); 
?>
Does anybody know what i would have to change in order to make the newest post appear at the top of the image?

note:
I have tried fopen($filename,'r+'); but it just overwrote the top entry meaning there was only ever 1 post on the text file.

thanks

Last edited by Handle; 02-13-05 at 09:05 AM. Reason: spelling
Reply With Quote
  #2 (permalink)  
Old 02-13-05, 12:20 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Reply With Quote
  #3 (permalink)  
Old 02-13-05, 12:32 PM
Handle Handle is offline
New Member
 
Join Date: Feb 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Hi mdhall. That link looked like it would of fixed the problem.
However, i was told of a simple solution in the script that creates the image.

I replaced
PHP Code:

$file file('shouts.txt'); 

With
PHP Code:

$file array_reverse(file('shouts.txt')); 

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
reading text from a file waji ASP 2 11-09-04 11:41 PM
Excel document containing records, need to save as a text file to upload to mysql bearslife PHP 1 06-05-04 03:24 AM
picking random entries with a filter... Double selection problem dsumpter PHP 7 11-16-03 07:19 PM
Editing a text file. cjh_60 PHP 1 10-14-03 03:59 PM


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