Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Prosty Shoutbox
Forum PHP.pl > Forum > Przedszkole
Arsanael
Mam mały problem z shoutboxem. Udało mi sie go zrobić ale problemem jest to ze nowe wiadomosi dodają sie na koncu gdyż w funkcji fopen uzylem atrubutu "a" gdyz nie kasuje reszty pliku. Teraz pytanie jak zrobić tak zeby bylo dobrze i nowe shouty dodawały sie na poczatku ?

kod:

  1. function add_shout($message,$from_user,$data,$time,$handle)
  2. {
  3. $file = fopen($handle,"a");
  4. fputs($file,$data);
  5. fputs($file,' - ');
  6. fputs($file,$time);
  7. fputs($file,' ( ');
  8. fputs($file,$from_user);
  9. fputs($file,' ) : ');
  10. fputs($file,$message);
  11. fputs($file, ' | ');
  12. fclose($file);
  13. header("Location: index.php");
  14. }


slightyboy
Skorzystaj z file_get_contents i file_put_contents. Po pobraniu źródła pliku po prostu dodawaj na początku nowy wpis i zapisuj całość do pliku. smile.gif
Flameman
Na przykład:
  1. function add_shout($message,$from_user,$data,$time,$file_name)
  2. {
  3. $zm .= $data.' - '.$time.' ( ').$from_user.' ) : '.$message. ' | ';
  4. $zm .= file_get_contents($file_name);
  5. file_put_contents($file_name,$zm);
  6. header("Location: index.php");
  7. }

Wybacz,że się tak podpinam,ale miałem już napisany kod i szkoda mi go było:P
EDIT:Poprawione
Fafu
w 4 lini powinno być
  1. $zm.= file_get_contents($file_name);
Arsanael
działa, dzieki wszytskim =)
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.