123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- --TEST--
- Test fwrite() function : usage variations - a, ab, at, a+, a+b & a+t mode
- --SKIPIF--
- <?php
- if( substr(PHP_OS, 0, 3) != 'WIN' ) {
- die('skip...Not valid for Linux');
- }
- ?>
- --FILE--
- <?php
- echo "*** Testing fwrite() various operations ***\n";
- // include the file.inc for Function: function delete_file($filename)
- include ("file.inc");
- /*
- Test fwrite with file opened in mode : a,ab,at,a+,a+b,a+
- File having content of type numeric, text,text_with_new_line & alphanumeric
- */
- $file_modes = array("a","ab","at","a+","a+b","a+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";
- /* open the file using $files_modes and perform fwrite() on it */
- foreach($file_modes as $file_mode) {
- echo "-- Opening file in $file_mode --\n";
- // create temp file and fill it content of type $file_content_type
- $filename = __DIR__."/fwrite_variation3.tmp"; // this is name of the file
- create_files ( __DIR__, 1, $file_content_type, 0755, 1, "w", "fwrite_variation", 3);
- $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); //get the data of size 1024
- /* Write the data into the file, verify it by checking the file pointer position, eof position,
- filesize & by displaying the content */
- // append the data to the file, starting from current position of the file pointer
- var_dump( ftell($file_handle) ); // expected: 1024
- var_dump( fwrite($file_handle,$data_to_be_written,400) );
- var_dump( ftell($file_handle) ); // expected: 1024 + 400
- var_dump( feof($file_handle) ); // expected : true
- /*overwrite data in middle of the file*/
- fseek($file_handle, SEEK_SET, (1024 + 400)/2 );
- var_dump( ftell($file_handle)); // expected: (1024 + 400)/2
- var_dump( fwrite($file_handle, $data_to_be_written, 200) );
- var_dump( ftell($file_handle) );
- var_dump( feof($file_handle) ); //Expecting bool(false)
- /* check the filesize and display file content */
- // close the file, get the size and content of the file.
- var_dump( fclose($file_handle) );
- clearstatcache();//clears file status cache
- var_dump( filesize($filename) );
- var_dump(md5(file_get_contents($filename)));
- // delete the file created
- delete_file($filename); // delete file with name fwrite_variation3.tmp
- } // end of inner foreach loop
- } // end of outer foreach loop
- echo "Done\n";
- ?>
- --EXPECT--
- *** Testing fwrite() various operations ***
- -- Testing fwrite() with file having content of type numeric --
- -- Opening file in a --
- int(0)
- int(400)
- int(400)
- bool(false)
- int(400)
- int(200)
- int(600)
- bool(false)
- bool(true)
- int(1624)
- string(32) "59ce5bf03b69069d00d6354bdc969ff6"
- -- Opening file in ab --
- int(0)
- int(400)
- int(400)
- bool(false)
- int(400)
- int(200)
- int(600)
- bool(false)
- bool(true)
- int(1624)
- string(32) "59ce5bf03b69069d00d6354bdc969ff6"
- -- Opening file in at --
- int(0)
- int(400)
- int(400)
- bool(false)
- int(400)
- int(200)
- int(600)
- bool(false)
- bool(true)
- int(1624)
- string(32) "59ce5bf03b69069d00d6354bdc969ff6"
- -- Opening file in a+ --
- int(0)
- int(400)
- int(400)
- bool(false)
- int(400)
- int(200)
- int(600)
- bool(false)
- bool(true)
- int(1624)
- string(32) "59ce5bf03b69069d00d6354bdc969ff6"
- -- Opening file in a+b --
- int(0)
- int(400)
- int(400)
- bool(false)
- int(400)
- int(200)
- int(600)
- bool(false)
- bool(true)
- int(1624)
- string(32) "59ce5bf03b69069d00d6354bdc969ff6"
- -- Opening file in a+t --
- int(0)
- int(400)
- int(400)
- bool(false)
- int(400)
- int(200)
- int(600)
- bool(false)
- bool(true)
- int(1624)
- string(32) "59ce5bf03b69069d00d6354bdc969ff6"
- -- Testing fwrite() with file having content of type text --
- -- Opening file in a --
- int(0)
- int(400)
- int(400)
- bool(false)
- int(400)
- int(200)
- int(600)
- bool(false)
- bool(true)
- int(1624)
- string(32) "dbd9dffd809d82e299bc1e5c55087f3b"
- -- Opening file in ab --
- int(0)
- int(400)
- int(400)
- bool(false)
- int(400)
- int(200)
- int(600)
- bool(false)
- bool(true)
- int(1624)
- string(32) "dbd9dffd809d82e299bc1e5c55087f3b"
- -- Opening file in at --
- int(0)
- int(400)
- int(400)
- bool(false)
- int(400)
- int(200)
- int(600)
- bool(false)
- bool(true)
- int(1624)
- string(32) "dbd9dffd809d82e299bc1e5c55087f3b"
- -- Opening file in a+ --
- int(0)
- int(400)
- int(400)
- bool(false)
- int(400)
- int(200)
- int(600)
- bool(false)
- bool(true)
- int(1624)
- string(32) "dbd9dffd809d82e299bc1e5c55087f3b"
- -- Opening file in a+b --
- int(0)
- int(400)
- int(400)
- bool(false)
- int(400)
- int(200)
- int(600)
- bool(false)
- bool(true)
- int(1624)
- string(32) "dbd9dffd809d82e299bc1e5c55087f3b"
- -- Opening file in a+t --
- int(0)
- int(400)
- int(400)
- bool(false)
- int(400)
- int(200)
- int(600)
- bool(false)
- bool(true)
- int(1624)
- string(32) "dbd9dffd809d82e299bc1e5c55087f3b"
- -- Testing fwrite() with file having content of type text_with_new_line --
- -- Opening file in a --
- int(0)
- int(400)
- int(400)
- bool(false)
- int(400)
- int(200)
- int(600)
- bool(false)
- bool(true)
- int(1624)
- string(32) "3f0a483fe8a2f405677844e0b1af6cf4"
- -- Opening file in ab --
- int(0)
- int(400)
- int(400)
- bool(false)
- int(400)
- int(200)
- int(600)
- bool(false)
- bool(true)
- int(1624)
- string(32) "3f0a483fe8a2f405677844e0b1af6cf4"
- -- Opening file in at --
- int(0)
- int(400)
- int(400)
- bool(false)
- int(400)
- int(200)
- int(600)
- bool(false)
- bool(true)
- int(1690)
- string(32) "656648355b64df6fded53b12fb355ab8"
- -- Opening file in a+ --
- int(0)
- int(400)
- int(400)
- bool(false)
- int(400)
- int(200)
- int(600)
- bool(false)
- bool(true)
- int(1624)
- string(32) "3f0a483fe8a2f405677844e0b1af6cf4"
- -- Opening file in a+b --
- int(0)
- int(400)
- int(400)
- bool(false)
- int(400)
- int(200)
- int(600)
- bool(false)
- bool(true)
- int(1624)
- string(32) "3f0a483fe8a2f405677844e0b1af6cf4"
- -- Opening file in a+t --
- int(0)
- int(400)
- int(400)
- bool(false)
- int(400)
- int(200)
- int(600)
- bool(false)
- bool(true)
- int(1690)
- string(32) "656648355b64df6fded53b12fb355ab8"
- -- Testing fwrite() with file having content of type alphanumeric --
- -- Opening file in a --
- int(0)
- int(400)
- int(400)
- bool(false)
- int(400)
- int(200)
- int(600)
- bool(false)
- bool(true)
- int(1624)
- string(32) "ea0c0bfa0b10aa8e614fd33ffe295cb9"
- -- Opening file in ab --
- int(0)
- int(400)
- int(400)
- bool(false)
- int(400)
- int(200)
- int(600)
- bool(false)
- bool(true)
- int(1624)
- string(32) "ea0c0bfa0b10aa8e614fd33ffe295cb9"
- -- Opening file in at --
- int(0)
- int(400)
- int(400)
- bool(false)
- int(400)
- int(200)
- int(600)
- bool(false)
- bool(true)
- int(1624)
- string(32) "ea0c0bfa0b10aa8e614fd33ffe295cb9"
- -- Opening file in a+ --
- int(0)
- int(400)
- int(400)
- bool(false)
- int(400)
- int(200)
- int(600)
- bool(false)
- bool(true)
- int(1624)
- string(32) "ea0c0bfa0b10aa8e614fd33ffe295cb9"
- -- Opening file in a+b --
- int(0)
- int(400)
- int(400)
- bool(false)
- int(400)
- int(200)
- int(600)
- bool(false)
- bool(true)
- int(1624)
- string(32) "ea0c0bfa0b10aa8e614fd33ffe295cb9"
- -- Opening file in a+t --
- int(0)
- int(400)
- int(400)
- bool(false)
- int(400)
- int(200)
- int(600)
- bool(false)
- bool(true)
- int(1624)
- string(32) "ea0c0bfa0b10aa8e614fd33ffe295cb9"
- Done
|