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”;
}

?>

發表迴響

Copy Protected by Chetan's WP-Copyprotect.