程式
//'7.1'處理時間標記
$session_name = $session_txt['7.1'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";
$fn = $file_name = ROOT_PATH."/test/6-10.txt";
print "$fn was last accessed on:". fileatime ($fn)."<br>";
print "$fn was last change on:". filectime ($fn)."<br>";
print "$fn was last modified on:". filemtime ($fn)."<br>";
if (touch ($fn,$date)){
print "Timestamp changed....";
}else{
print "Modification Failed";
}
$message="
<fieldset><legend><font color=red>TIPS</font></legend>
在PHP中,copy()是更改檔案時間標記的唯一方式,而它唯一變更<br>
的是檔案修改時間。因此,除非你用exec(),system()跳出PHP之外<br>
,否則你只能更改檔案的mtime。
<br>
</fieldset>
";
echo $message."<br>";
//'7.2'移除檔案
$session_name = $session_txt['7.2'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";
$message="
<fieldset><legend><font color=red>TIPS</font></legend>
用unlink()函式處理你要刪除的檔案。若成功傳回1,否則傳回0。<br>
因此你可以用or運算子或if-else區塊。<br>
如果你想刪除數個檔案,你可以用forch迴圈讀取陣列元素,然後<br>
刪除每個檔案。<br>
foreach (\$file as \$file){ <br>
unlink(\$file); <br>
or die ('Waring str');<br>
}
<br>
</fieldset>
";
echo $message."<br>";
//'7.3'拷貝或移動檔案
$session_name = $session_txt['7.3'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";
$message="
<fieldset><legend><font color=red>TIPS</font></legend>
在PHP中,copy()函式<br>
if (copy(\$orginal,\$new)){<br>
print '成功'; <br>
}else{ <br>
print '失敗'; <br>
} <br>
或者如果你需要移動檔案,就用rename()函式 <br>
rename(\$original,\$new) <br>
or die ('warmingstr')
<br>
</fieldset>
";
echo $message."<br>";
//'7.5'分析檔名的各個組成部分
$session_name = $session_txt['7.5'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";
$fn = ROOT_PATH."/test/6-11.php";
$pinfo = pathinfo ($fn);
print "Directory name is :".$pinfo [dirname ] ."\n<br>";
print "Filename is :".$pinfo [basename ]." \n<br>";
print "Ending is :".$pinfo [extension ]." \n<br>";
$message="
<fieldset><legend><font color=red>TIPS</font></legend>
參數 dirname 檔案位在的目錄<br>
參數 basename 檔案名稱<br>
參數 extension 檔案副檔名,若它有的話
<br>
</fieldset>
";
echo $message."<br>";
//'7.8'循序處裡目錄中的檔案
$session_name = $session_txt['7.8'];
echo $session_name."<br>";
//echo ROOT_PATH."<br>";
$dir_name = ROOT_PATH."/test";
$dh = dir ($dir_name);
echo "方法一<br>";
while ($entry = $dh ->read()){
print $entry ."\n";
}
$dh->close();
$dh = opendir ($dir_name);
echo "<br>方法二<br>";
while ($entry = readdir ($dh)){
print $entry ."\n";
}
closedir();
$message="
<fieldset><legend><font color=red>TIPS</font></legend>
你可以用dir()函式透過一虛擬的物件處裡目錄或用opendir()<br>
、readdir()、和closedir()來讀取目錄。
<br>
</fieldset>
";
echo $message."<br>";