查詢

filectime()函式—用法及示例

「 獲取指定檔案的建立時間 」


函式名:filectime()

適用版本:PHP 4, PHP 5, PHP 7

用法:filectime() 函式用於獲取指定檔案的建立時間。該函式返回一個 Unix 時間戳,表示檔案的建立時間。

語法:filectime ( string $filename ) : int

引數:

  • filename:必需,要獲取建立時間的檔案路徑。

返回值:返回一個整數型別的 Unix 時間戳,表示檔案的建立時間。

示例:

$filename = "test.txt";
$ctime = filectime($filename);

echo "檔案的建立時間是:" . date("Y-m-d H:i:s", $ctime);

輸出:

檔案的建立時間是:2022-01-01 10:30:00

注意事項:

  • 使用 filectime() 函式需要確保檔案存在且可讀。
  • 如果檔案不存在或無法讀取,該函式將返回 false。
  • filectime() 函式返回的時間戳是 Unix 時間戳,需要使用 date() 函式將其轉換為可讀的日期時間格式。
補充糾錯
上一個函式: filegroup()函式
下一個函式: fileatime()函式
熱門PHP函式
分享連結