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