2014-12-03 3 views
0

fuction fopen으로 시도했지만 fwrite하지만 여전히 가능하지는 않습니다. 내 ajax 방명록을 txt 파일로 저장하고 싶습니다. 도와주세요. 이는 index.php를파일에 ajax 방명록 저장하기

<?php 
error_reporting(E_ALL^E_NOTICE); 

include "comment.class.php"; 

$comments = array(); 

foreach($comments as $c){ 
    echo $c->markup(); 
} 

?> 

이며, 그것은 comment.class.php

<?php 

class Comment 
{ 
    private $data = array(); 

    public function __construct($row) 
    { 
     /* 
     / konstruktor 
     */ 

     $this->data = $row; 
    } 

    public function markup() 
    { 
     /* 
     / method untuk comment 
     */ 

     //alias untuk &$this->data 
     $d = &$this->data; 

     $link_open = ''; 
     $link_close = ''; 

     if($d['url']){ 


      $link_open = '<a href="'.$d['url'].'">'; 
      $link_close = '</a>'; 
     } 

     $d['dt'] = strtotime($d['dt']); 
     $url = 'http://'.dirname($_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]).'/img/default_avatar.gif'; 

     return ' 

      <div class="comment"> 
       <div class="avatar"> 
        '.$link_open.' 
        '.$link_close.' 
       </div> 

       <div class="name">'.$link_open.$d['name'].$link_close.'</div> 
       <div class="date" title="Added at '.date('H:i \o\n d M Y',$d['dt']).'">'.date('d M Y',$d['dt']).'</div> 
       <p>'.$d['body'].'</p> 
      </div> 
     '; 
    } 

내가 chat.txt에

답변

0

다음 코드를 추가합니다 주석 몸을 저장할 것입니다 주석을 파일에 에코하는 대신 파일에 넣습니다. 자세한 내용은 file_put_contents manual을 참조하십시오.

foreach($comments as $c){ 
    file_put_contents('chat.txt', $c->markup(), FILE_APPEND); 
} 
+0

나는 아직도 할 수 없다. –