1--TEST--
2Test filesize() function: usage variations - file size after truncate
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) != 'WIN') {
6    die('skip only valid for Windows');
7}
8--FILE--
9<?php
10/*
11 Prototype   : int filesize ( string $filename );
12 Description : Returns the size of the file in bytes, or FALSE
13   (and generates an error of level E_WARNING) in case of an error.
14*/
15
16$file_path = dirname(__FILE__);
17
18echo "*** Testing filesize(): usage variations ***\n";
19$filename =  $file_path."/filesize_variation3.tmp";
20$file_handle = fopen($filename, "w");
21fwrite($file_handle, (binary)str_repeat("Hello,World ", 1000) ); // create file of size 12000 bytes
22fclose($file_handle);
23
24echo "-- Testing filesize() after truncating the file to a new length --\n";
25// truncate the file created earlier in subdir, the size of the file is 12000bytes
26// truncate the same file, in the loop , each time with the decrement in size by 1200 bytes,
27//  until -1200bytes size
28for($size = filesize($filename); $size>=-1200; $size-=1200) {
29  $file_handle = fopen($filename, "r+");
30  var_dump( ftruncate($file_handle, $size) );
31  fclose($file_handle);
32  var_dump( filesize($filename) );
33  clearstatcache();
34}
35
36echo "*** Done ***\n";
37?>
38--CLEAN--
39<?php
40$file_path = dirname(__FILE__);
41unlink($file_path."/filesize_variation3.tmp");
42?>
43--EXPECTF--
44*** Testing filesize(): usage variations ***
45-- Testing filesize() after truncating the file to a new length --
46bool(true)
47int(12000)
48bool(true)
49int(10800)
50bool(true)
51int(9600)
52bool(true)
53int(8400)
54bool(true)
55int(7200)
56bool(true)
57int(6000)
58bool(true)
59int(4800)
60bool(true)
61int(3600)
62bool(true)
63int(2400)
64bool(true)
65int(1200)
66bool(true)
67int(0)
68
69Warning: ftruncate(): Negative size is not supported in %s on line %d
70bool(false)
71int(0)
72*** Done ***
73