Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function put_post($topicid, $post, $username, $datafile="wypowiedzi.txt", $separator=":-:")
- {
- // ostatni wiersz zawiera najmłodszy wpis
- if(is_file($datafile)){
- // odczyt pliku
- $data=file($datafile);
- // pobranie danych z ostatniego elementu tablicy $data
- $record = explode($separator, trim(array_pop($data)));
- $postid = $record[0]+1;
- } else {
- $postid = 1;
- }
- // utworzenie nowego wiersz danych
- // zakodowanie przez bin2hex() danych przesłanych przez użtykownika
- $data = implode($separator,
- array($postid,
- $topicid,
- bin2hex($post),
- bin2hex($username),
- date("Y-m-d H:i:s")
- )
- );
- // zapis danych na końcu pliku
- if( $fh = fopen($datafile, "a+")){
- fwrite($fh, $data."\n");
- fclose($fh);
- return $postid;
- }else{
- return FALSE;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement