Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Prosty Shoutbox
Arsanael
post 26.08.2009, 00:52:44
Post #1





Grupa: Zarejestrowani
Postów: 65
Pomógł: 0
Dołączył: 4.06.2009

Ostrzeżenie: (0%)
-----


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. }


Go to the top of the page
+Quote Post
slightyboy
post 26.08.2009, 01:22:06
Post #2





Grupa: Zarejestrowani
Postów: 52
Pomógł: 12
Dołączył: 12.07.2007

Ostrzeżenie: (0%)
-----


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
Go to the top of the page
+Quote Post
Flameman
post 26.08.2009, 01:31:43
Post #3





Grupa: Zarejestrowani
Postów: 9
Pomógł: 1
Dołączył: 21.08.2009

Ostrzeżenie: (0%)
-----


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

Ten post edytował Flameman 26.08.2009, 13:34:04
Go to the top of the page
+Quote Post
Fafu
post 26.08.2009, 03:55:14
Post #4





Grupa: Zarejestrowani
Postów: 243
Pomógł: 33
Dołączył: 30.01.2008
Skąd: Wrocław

Ostrzeżenie: (0%)
-----


w 4 lini powinno być
  1. $zm.= file_get_contents($file_name);


--------------------
http://rafal.brzezinski.me - skrypty, tutoriale i inne.
Jeśli udało Ci się rozwiązać problem podziękuj osobom, które ci pomogły.
Go to the top of the page
+Quote Post
Arsanael
post 26.08.2009, 13:53:33
Post #5





Grupa: Zarejestrowani
Postów: 65
Pomógł: 0
Dołączył: 4.06.2009

Ostrzeżenie: (0%)
-----


działa, dzieki wszytskim =)
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 24.07.2025 - 13:07