PHP ftruncate()関数
❮PHPファイルシステムリファレンス例
開いているファイルを指定された長さ(100バイト)に切り捨てます。
<?php
// Check filesize
echo filesize("test.txt");
echo "<br>";
$file = fopen("test.txt", "a+");
ftruncate($file,100);
fclose($file);
// Clear cache and check filesize again
clearstatcache();
echo filesize("test.txt");
?>
上記のコードの出力は次のようになります。
792
100
定義と使用法
ftruncate()関数は、開いているファイルを指定された長さに切り捨てます。
構文
ftruncate(file, size)
パラメータ値
Parameter | Description |
---|---|
file | Required. Specifies the open file to truncate |
size | Required. Specifies the new file size |
技術的な詳細
戻り値: | 成功した場合はTRUE、失敗した場合はFALSE。 |
---|---|
PHPバージョン: | 4.0以降 |
❮PHPファイルシステムリファレンス