/var/log/masayoshi/masayoshi.life.log

とりあえず、書きたいこと書くだけ。

ファイル編集クラス(ソースコード)



次の通りです。


class file_control{
var $file = "" ;//処理するファイルの指定
var $title = "" ;//ファイルの表題
var $content = "" ;//ファイルの内容
var $mode = "" ;//ファイルの読み出し・書き出しのモード設定
//操作するファイルを指定する
function file_control($co_file,$acc_mode,$title,$content){
$this->file = $co_file ;
$this->mode = $acc_mode ;
switch($acc_mode){
case title_in :
if($content == true){
$this->content = $title."\n".$content ;
}else{
$this->content = "" ;
}
break ;
default :
if($content == true){
$this->content = $content."\n" ;
}else{
$this->content = "" ;
}
break ;
}
}
/*ファイル有無を判断
function file_catch($file){
return "ko" ;
}*/
//ファイルの編集作業
function file_acc($mode){
/* n=新規作成 w=上書き r=読み込み a=追記 */
switch($mode){
case n://新規作成
touch($this->file) ;
chmod($this->file,0666) ;
$file_acc = @fopen($this->file,"w");
flock($file_acc,LOCK_EX) ;
fputs($file_acc,$this->content) ;
flock($file_acc,LOCK_UN) ;
fclose($file_acc) ;
break ;
case r://読みだす
$file_acc = @fopen($this->file,"r") ;
$i = 0 ;
if($this->mode == "title_in"){
while(!feof($file_acc)){
if($i == 0){
$data["title"] = fgets($file_acc) ;
$i++ ;
}else{
$data["content"] = fgets($file_acc) ;
$i++ ;
}
}
}else{
while(!feof($file_acc)){
$data["content"][$i] = fgets($file_acc) ;
$i++ ;
}
}
fclose($file_acc) ;
return $data ;
break ;
default://その他
$file_acc = @fopen($this->file,$mode) ;
flock($file_acc,LOCK_EX) ;
fputs($file_acc,$this->content) ;
flock($file_acc,LOCK_UN) ;
fclose($file_acc) ;
break ;
}

}
//ファイルを読み込む、アクセサ使わず
function file_open2(){
$this->content =file_get_contents($this->file) ;
}
//戻す
function retu(){
return mb_convert_encoding($this->content,"EUC","auto") ;
}
//ファイルの削除
function file_del(){
return unlink($this->file) ;
}
}
?>


詳しくない説明はこちらで配信しているファイルに納めてあります。


無駄な箇所はありますがそれは気にしないでください、バージョンアップした際はここで通知いたします。