1--TEST-- 2Test fseek(), ftell() & rewind() functions : usage variations - all w and x modes, default whence 3--SKIPIF-- 4<?php 5if( substr(PHP_OS, 0, 3) == "WIN" ) 6 die("skip.. Not valid for Windows"); 7?> 8--FILE-- 9<?php 10// include the file.inc for common functions for test 11include ("file.inc"); 12 13/* Testing fseek(),ftell(),rewind() functions 14 1. All write and create with write modes 15 2. Testing fseek() without using argument whence 16*/ 17 18echo "*** Testing fseek(), ftell(), rewind() : default whence & all w and x modes ***\n"; 19$file_modes = array( "w","wb","wt","w+","w+b","w+t", 20 "x","xb","xt","x+","x+b","x+t"); 21$file_content_types = array( "text_with_new_line","alphanumeric"); 22 23$offset = array(-1, 0, 1, 513); // different offsets, including negative and beyond size 24 25$filename = __DIR__."/fseek_ftell_rewind_variation2.tmp"; // this is name of the file created by create_files() 26 27/* open the file using $files_modes and perform fseek(),ftell() and rewind() on it */ 28foreach($file_content_types as $file_content_type){ 29 echo "\n-- File having data of type ". $file_content_type ." --\n"; 30 31 foreach($file_modes as $file_mode) { 32 echo "-- File opened in mode ".$file_mode." --\n"; 33 $file_handle = fopen($filename, $file_mode); 34 if (!$file_handle){ 35 echo "Error: failed to fopen() file: $filename!"; 36 exit(); 37 } 38 $data_to_be_written=""; 39 fill_buffer($data_to_be_written, $file_content_type, 512); //get the data of size 512 40 $data_to_be_written = $data_to_be_written; 41 fwrite($file_handle,$data_to_be_written); 42 rewind($file_handle); 43 44 echo "-- Testing fseek() without using argument whence --\n"; 45 foreach($offset as $count){ 46 var_dump( fseek($file_handle,$count) ); 47 var_dump( ftell($file_handle) ); // confirm the file pointer position 48 var_dump( feof($file_handle) ); //ensure that file pointer is not at end 49 } //end of offset loop 50 51 //close the file and check the size 52 fclose($file_handle); 53 var_dump( filesize($filename) ); 54 55 delete_file($filename); // delete file with name 56 } //end of file_mode loop 57} //end of file_content_types loop 58 59echo "Done\n"; 60?> 61--EXPECT-- 62*** Testing fseek(), ftell(), rewind() : default whence & all w and x modes *** 63 64-- File having data of type text_with_new_line -- 65-- File opened in mode w -- 66-- Testing fseek() without using argument whence -- 67int(-1) 68int(0) 69bool(false) 70int(0) 71int(0) 72bool(false) 73int(0) 74int(1) 75bool(false) 76int(0) 77int(513) 78bool(false) 79int(512) 80-- File opened in mode wb -- 81-- Testing fseek() without using argument whence -- 82int(-1) 83int(0) 84bool(false) 85int(0) 86int(0) 87bool(false) 88int(0) 89int(1) 90bool(false) 91int(0) 92int(513) 93bool(false) 94int(512) 95-- File opened in mode wt -- 96-- Testing fseek() without using argument whence -- 97int(-1) 98int(0) 99bool(false) 100int(0) 101int(0) 102bool(false) 103int(0) 104int(1) 105bool(false) 106int(0) 107int(513) 108bool(false) 109int(512) 110-- File opened in mode w+ -- 111-- Testing fseek() without using argument whence -- 112int(-1) 113int(0) 114bool(false) 115int(0) 116int(0) 117bool(false) 118int(0) 119int(1) 120bool(false) 121int(0) 122int(513) 123bool(false) 124int(512) 125-- File opened in mode w+b -- 126-- Testing fseek() without using argument whence -- 127int(-1) 128int(0) 129bool(false) 130int(0) 131int(0) 132bool(false) 133int(0) 134int(1) 135bool(false) 136int(0) 137int(513) 138bool(false) 139int(512) 140-- File opened in mode w+t -- 141-- Testing fseek() without using argument whence -- 142int(-1) 143int(0) 144bool(false) 145int(0) 146int(0) 147bool(false) 148int(0) 149int(1) 150bool(false) 151int(0) 152int(513) 153bool(false) 154int(512) 155-- File opened in mode x -- 156-- Testing fseek() without using argument whence -- 157int(-1) 158int(0) 159bool(false) 160int(0) 161int(0) 162bool(false) 163int(0) 164int(1) 165bool(false) 166int(0) 167int(513) 168bool(false) 169int(512) 170-- File opened in mode xb -- 171-- Testing fseek() without using argument whence -- 172int(-1) 173int(0) 174bool(false) 175int(0) 176int(0) 177bool(false) 178int(0) 179int(1) 180bool(false) 181int(0) 182int(513) 183bool(false) 184int(512) 185-- File opened in mode xt -- 186-- Testing fseek() without using argument whence -- 187int(-1) 188int(0) 189bool(false) 190int(0) 191int(0) 192bool(false) 193int(0) 194int(1) 195bool(false) 196int(0) 197int(513) 198bool(false) 199int(512) 200-- File opened in mode x+ -- 201-- Testing fseek() without using argument whence -- 202int(-1) 203int(0) 204bool(false) 205int(0) 206int(0) 207bool(false) 208int(0) 209int(1) 210bool(false) 211int(0) 212int(513) 213bool(false) 214int(512) 215-- File opened in mode x+b -- 216-- Testing fseek() without using argument whence -- 217int(-1) 218int(0) 219bool(false) 220int(0) 221int(0) 222bool(false) 223int(0) 224int(1) 225bool(false) 226int(0) 227int(513) 228bool(false) 229int(512) 230-- File opened in mode x+t -- 231-- Testing fseek() without using argument whence -- 232int(-1) 233int(0) 234bool(false) 235int(0) 236int(0) 237bool(false) 238int(0) 239int(1) 240bool(false) 241int(0) 242int(513) 243bool(false) 244int(512) 245 246-- File having data of type alphanumeric -- 247-- File opened in mode w -- 248-- Testing fseek() without using argument whence -- 249int(-1) 250int(0) 251bool(false) 252int(0) 253int(0) 254bool(false) 255int(0) 256int(1) 257bool(false) 258int(0) 259int(513) 260bool(false) 261int(512) 262-- File opened in mode wb -- 263-- Testing fseek() without using argument whence -- 264int(-1) 265int(0) 266bool(false) 267int(0) 268int(0) 269bool(false) 270int(0) 271int(1) 272bool(false) 273int(0) 274int(513) 275bool(false) 276int(512) 277-- File opened in mode wt -- 278-- Testing fseek() without using argument whence -- 279int(-1) 280int(0) 281bool(false) 282int(0) 283int(0) 284bool(false) 285int(0) 286int(1) 287bool(false) 288int(0) 289int(513) 290bool(false) 291int(512) 292-- File opened in mode w+ -- 293-- Testing fseek() without using argument whence -- 294int(-1) 295int(0) 296bool(false) 297int(0) 298int(0) 299bool(false) 300int(0) 301int(1) 302bool(false) 303int(0) 304int(513) 305bool(false) 306int(512) 307-- File opened in mode w+b -- 308-- Testing fseek() without using argument whence -- 309int(-1) 310int(0) 311bool(false) 312int(0) 313int(0) 314bool(false) 315int(0) 316int(1) 317bool(false) 318int(0) 319int(513) 320bool(false) 321int(512) 322-- File opened in mode w+t -- 323-- Testing fseek() without using argument whence -- 324int(-1) 325int(0) 326bool(false) 327int(0) 328int(0) 329bool(false) 330int(0) 331int(1) 332bool(false) 333int(0) 334int(513) 335bool(false) 336int(512) 337-- File opened in mode x -- 338-- Testing fseek() without using argument whence -- 339int(-1) 340int(0) 341bool(false) 342int(0) 343int(0) 344bool(false) 345int(0) 346int(1) 347bool(false) 348int(0) 349int(513) 350bool(false) 351int(512) 352-- File opened in mode xb -- 353-- Testing fseek() without using argument whence -- 354int(-1) 355int(0) 356bool(false) 357int(0) 358int(0) 359bool(false) 360int(0) 361int(1) 362bool(false) 363int(0) 364int(513) 365bool(false) 366int(512) 367-- File opened in mode xt -- 368-- Testing fseek() without using argument whence -- 369int(-1) 370int(0) 371bool(false) 372int(0) 373int(0) 374bool(false) 375int(0) 376int(1) 377bool(false) 378int(0) 379int(513) 380bool(false) 381int(512) 382-- File opened in mode x+ -- 383-- Testing fseek() without using argument whence -- 384int(-1) 385int(0) 386bool(false) 387int(0) 388int(0) 389bool(false) 390int(0) 391int(1) 392bool(false) 393int(0) 394int(513) 395bool(false) 396int(512) 397-- File opened in mode x+b -- 398-- Testing fseek() without using argument whence -- 399int(-1) 400int(0) 401bool(false) 402int(0) 403int(0) 404bool(false) 405int(0) 406int(1) 407bool(false) 408int(0) 409int(513) 410bool(false) 411int(512) 412-- File opened in mode x+t -- 413-- Testing fseek() without using argument whence -- 414int(-1) 415int(0) 416bool(false) 417int(0) 418int(0) 419bool(false) 420int(0) 421int(1) 422bool(false) 423int(0) 424int(513) 425bool(false) 426int(512) 427Done 428