1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- --TEST--
- ftruncate() tests
- --FILE--
- <?php
- $filename = __DIR__."/ftruncate.dat";
- file_put_contents($filename, "some test data inside");
- $fp = fopen($filename, "r");
- var_dump(ftruncate($fp, 10));
- fclose($fp);
- var_dump(file_get_contents($filename));
- $fp = fopen($filename, "w");
- var_dump(ftruncate($fp, 10));
- fclose($fp);
- var_dump(file_get_contents($filename));
- file_put_contents($filename, "some test data inside");
- $fp = fopen($filename, "a");
- var_dump(ftruncate($fp, 10));
- fclose($fp);
- var_dump(file_get_contents($filename));
- $fp = fopen($filename, "a");
- var_dump(ftruncate($fp, 0));
- fclose($fp);
- var_dump(file_get_contents($filename));
- file_put_contents($filename, "some test data inside");
- $fp = fopen($filename, "a");
- try {
- var_dump(ftruncate($fp, -1000000000));
- } catch (\ValueError $e) {
- echo $e->getMessage() . \PHP_EOL;
- }
- fclose($fp);
- var_dump(file_get_contents($filename));
- @unlink($filename);
- ?>
- --EXPECTF--
- bool(false)
- string(21) "some test data inside"
- bool(true)
- string(10) "%0%0%0%0%0%0%0%0%0%0"
- bool(true)
- string(10) "some test "
- bool(true)
- string(0) ""
- ftruncate(): Argument #2 ($size) must be greater than or equal to 0
- string(21) "some test data inside"
|