假設我們欲讀取/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”;
}
?>