易春木

Feed Rss

PHP: fopen 讀檔 example

08.31.2010, IT開發, 記事本, by , 2,385 人次 .

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

?>

閱讀這篇文章的讀者也會看:

發表迴響

您的電子郵件位址並不會被公開。 必要欄位標記為 *

*

您可以使用這些 HTML 標籤與屬性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>