public function set_viewer($action, $fid, $viewed = false, $viewed_day = false, $viewed_week = false, $viewed_month = false, $liked = false, $disliked = false){
$path = '/home/view.txt';
$file = file_get_contents($path);
if(strpos($file, "post-".$fid."|") !== FALSE && is_numeric($fid) && is_numeric($viewed) && is_numeric($viewed_day) && is_numeric($viewed_week) && is_numeric($viewed_month) && is_numeric($liked) && is_numeric($disliked)){
$lines = file($path);
foreach ($lines as $lineNumber => $line) {
if (strpos($line, "post-".$fid."|") !== FALSE) {
$cut = explode("|", trim($line));
if($action == "view"){
$replace = "post-".$fid."|".($cut[1]+1)."|".($cut[2]+1)."|".($cut[3]+1)."|".($cut[4]+1)."|".$cut[5]."|".$cut[6].PHP_EOL;
$str = str_replace($line, $replace , $file);
file_put_contents($path, $str);
}else if($action == "liked"){
$replace = "post-".$fid."|".$cut[1]."|".$cut[2]."|".$cut[3]."|".$cut[4]."|".($cut[5]+1)."|".$cut[6].PHP_EOL;
$str = str_replace($line, $replace , $file);
file_put_contents($path, $str);
}else if($action == "dislike"){
$replace = "post-".$fid."|".$cut[1]."|".$cut[2]."|".$cut[3]."|".$cut[4]."|".$cut[5]."|".($cut[6]+1).PHP_EOL;
$str = str_replace($line, $replace , $file);
file_put_contents($path, $str);
}
}
}
}else if(strpos($file, "post-".$fid."|") === FALSE && is_numeric($fid) && is_numeric($viewed) && is_numeric($viewed_day) && is_numeric($viewed_week) && is_numeric($viewed_month) && is_numeric($liked) && is_numeric($disliked)){
$insert = trim("post-".$fid."|".($viewed+1)."|".($viewed_day+1)."|".($viewed_week+1)."|".($viewed_month+1)."|".$liked."|".$disliked).PHP_EOL;
file_put_contents($path, $insert, FILE_APPEND);
}
}
Các B xem giúp e với. Thank!!Nhờ các cao thủ code giúp
laogiavn24/11/2021955 lượt xem15 bình luận
E đang gặp khó khăn và không hiểu function này site ở đâu mà file txt của em nó write trồng chéo lên nhau mà e ko biết fix kiểu gì.
Bình luận
Đang tải...
Đang kiểm tra đăng nhập...
