PHP: fopen 讀檔 example

假設我們欲讀取/tmp/upg_percent 檔

<?php

$file = “/tmp/upg_percent”;
$buf = “”;
if(file_exists($file)){
$fo = fopen($file, “r”);
if($fo != NULL){
while (!feof($fo)) {
$buf .= fgets($fo);
}
fclose($fo);
}
}
$percent =  intval($buf);

if($percent < 100) {
echo $percent;
}
else {
echo “100”;
}

?>

分類: 未分類

發表迴響