123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- --TEST--
- Test fwrite() function : usage variations - x, xb, xt, x+, x+b & x+t modes
- --SKIPIF--
- <?php
- if( substr(PHP_OS, 0, 3) == 'WIN' ) {
- die('skip...Not valid for Windows');
- }
- ?>
- --FILE--
- <?php
- echo "*** Testing fwrite() various operations ***\n";
- include ("file.inc");
- $file_modes = array("x","xb","xt","x+","x+b","x+t");
- $file_content_types = array("numeric","text","text_with_new_line","alphanumeric");
- foreach($file_content_types as $file_content_type) {
- echo "\n-- Testing fwrite() with file having content of type ". $file_content_type ." --\n";
-
- foreach($file_modes as $file_mode) {
- echo "-- Opening file in $file_mode --\n";
- $filename = __DIR__."/fwrite_variation4.tmp";
- $file_handle = fopen($filename, $file_mode);
- if(!$file_handle) {
- echo "Error: failed to fopen() file: $filename!";
- exit();
- }
- $data_to_be_written="";
- fill_buffer($data_to_be_written,$file_content_type,1024);
-
-
- var_dump( ftell($file_handle) );
- var_dump( fwrite($file_handle,$data_to_be_written,400));
- var_dump( ftell($file_handle) );
- var_dump( feof($file_handle) );
-
-
- var_dump( fclose($file_handle) );
- clearstatcache();
- var_dump( filesize($filename) );
- var_dump(md5(file_get_contents($filename)));
-
- delete_file($filename);
- }
- }
- echo "Done\n";
- ?>
- --EXPECT--
- *** Testing fwrite() various operations ***
- -- Testing fwrite() with file having content of type numeric --
- -- Opening file in x --
- int(0)
- int(400)
- int(400)
- bool(false)
- bool(true)
- int(400)
- string(32) "f255efe87ebdf755e515868cea9ad24b"
- -- Opening file in xb --
- int(0)
- int(400)
- int(400)
- bool(false)
- bool(true)
- int(400)
- string(32) "f255efe87ebdf755e515868cea9ad24b"
- -- Opening file in xt --
- int(0)
- int(400)
- int(400)
- bool(false)
- bool(true)
- int(400)
- string(32) "f255efe87ebdf755e515868cea9ad24b"
- -- Opening file in x+ --
- int(0)
- int(400)
- int(400)
- bool(false)
- bool(true)
- int(400)
- string(32) "f255efe87ebdf755e515868cea9ad24b"
- -- Opening file in x+b --
- int(0)
- int(400)
- int(400)
- bool(false)
- bool(true)
- int(400)
- string(32) "f255efe87ebdf755e515868cea9ad24b"
- -- Opening file in x+t --
- int(0)
- int(400)
- int(400)
- bool(false)
- bool(true)
- int(400)
- string(32) "f255efe87ebdf755e515868cea9ad24b"
- -- Testing fwrite() with file having content of type text --
- -- Opening file in x --
- int(0)
- int(400)
- int(400)
- bool(false)
- bool(true)
- int(400)
- string(32) "c2244282eeca7c2d32d0dacf21e19432"
- -- Opening file in xb --
- int(0)
- int(400)
- int(400)
- bool(false)
- bool(true)
- int(400)
- string(32) "c2244282eeca7c2d32d0dacf21e19432"
- -- Opening file in xt --
- int(0)
- int(400)
- int(400)
- bool(false)
- bool(true)
- int(400)
- string(32) "c2244282eeca7c2d32d0dacf21e19432"
- -- Opening file in x+ --
- int(0)
- int(400)
- int(400)
- bool(false)
- bool(true)
- int(400)
- string(32) "c2244282eeca7c2d32d0dacf21e19432"
- -- Opening file in x+b --
- int(0)
- int(400)
- int(400)
- bool(false)
- bool(true)
- int(400)
- string(32) "c2244282eeca7c2d32d0dacf21e19432"
- -- Opening file in x+t --
- int(0)
- int(400)
- int(400)
- bool(false)
- bool(true)
- int(400)
- string(32) "c2244282eeca7c2d32d0dacf21e19432"
- -- Testing fwrite() with file having content of type text_with_new_line --
- -- Opening file in x --
- int(0)
- int(400)
- int(400)
- bool(false)
- bool(true)
- int(400)
- string(32) "fa6c79b925c2fc754b9d063c6de1d8df"
- -- Opening file in xb --
- int(0)
- int(400)
- int(400)
- bool(false)
- bool(true)
- int(400)
- string(32) "fa6c79b925c2fc754b9d063c6de1d8df"
- -- Opening file in xt --
- int(0)
- int(400)
- int(400)
- bool(false)
- bool(true)
- int(400)
- string(32) "fa6c79b925c2fc754b9d063c6de1d8df"
- -- Opening file in x+ --
- int(0)
- int(400)
- int(400)
- bool(false)
- bool(true)
- int(400)
- string(32) "fa6c79b925c2fc754b9d063c6de1d8df"
- -- Opening file in x+b --
- int(0)
- int(400)
- int(400)
- bool(false)
- bool(true)
- int(400)
- string(32) "fa6c79b925c2fc754b9d063c6de1d8df"
- -- Opening file in x+t --
- int(0)
- int(400)
- int(400)
- bool(false)
- bool(true)
- int(400)
- string(32) "fa6c79b925c2fc754b9d063c6de1d8df"
- -- Testing fwrite() with file having content of type alphanumeric --
- -- Opening file in x --
- int(0)
- int(400)
- int(400)
- bool(false)
- bool(true)
- int(400)
- string(32) "b2a123e1d84e6a03c8520aff7689219e"
- -- Opening file in xb --
- int(0)
- int(400)
- int(400)
- bool(false)
- bool(true)
- int(400)
- string(32) "b2a123e1d84e6a03c8520aff7689219e"
- -- Opening file in xt --
- int(0)
- int(400)
- int(400)
- bool(false)
- bool(true)
- int(400)
- string(32) "b2a123e1d84e6a03c8520aff7689219e"
- -- Opening file in x+ --
- int(0)
- int(400)
- int(400)
- bool(false)
- bool(true)
- int(400)
- string(32) "b2a123e1d84e6a03c8520aff7689219e"
- -- Opening file in x+b --
- int(0)
- int(400)
- int(400)
- bool(false)
- bool(true)
- int(400)
- string(32) "b2a123e1d84e6a03c8520aff7689219e"
- -- Opening file in x+t --
- int(0)
- int(400)
- int(400)
- bool(false)
- bool(true)
- int(400)
- string(32) "b2a123e1d84e6a03c8520aff7689219e"
- Done
|