1--TEST-- 2Test fseek(), ftell() & rewind() functions : usage variations - all r & a modes, SEEK_CUR 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() with whence = SEEK_CUR 11*/ 12echo "*** Testing fseek(), ftell(), rewind() : whence = SEEK_CUR & all r and a modes ***\n"; 13 14$file_modes = array( "r","rb","rt","r+","r+b","r+t", 15 "a","ab","at","a+","a+b","a+t"); 16$file_content_types = array( "text_with_new_line","alphanumeric"); 17 18$offset = array(-1, 0, 1, 512, 600);// different offsets 19 20$filename = __DIR__."/fseek_ftell_rewind_variation5.tmp"; // this is name of the file created by create_files() 21 22/* open the file using $files_modes and perform fseek(),ftell() and rewind() on it */ 23foreach($file_content_types as $file_content_type){ 24 echo "-- File having data of type ". $file_content_type ." --\n"; 25 26 foreach($file_modes as $file_mode) { 27 echo "-- File opened in mode ".$file_mode." --\n"; 28 create_files ( __DIR__, 1, $file_content_type, 0755, 512, "w", "fseek_ftell_rewind_variation" 29 ,5,"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 rewind($file_handle); 36 foreach($offset as $count){ 37 var_dump( fseek($file_handle,$count,SEEK_CUR) ); 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() : whence = SEEK_CUR & all r and a modes *** 54-- File having data of type text_with_new_line -- 55-- File opened in mode r -- 56int(-1) 57int(0) 58bool(false) 59int(0) 60int(0) 61bool(false) 62int(0) 63int(1) 64bool(false) 65int(0) 66int(513) 67bool(false) 68int(0) 69int(1113) 70bool(false) 71int(512) 72-- File opened in mode rb -- 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(0) 86int(1113) 87bool(false) 88int(512) 89-- File opened in mode rt -- 90int(-1) 91int(0) 92bool(false) 93int(0) 94int(0) 95bool(false) 96int(0) 97int(1) 98bool(false) 99int(0) 100int(513) 101bool(false) 102int(0) 103int(1113) 104bool(false) 105int(512) 106-- File opened in mode r+ -- 107int(-1) 108int(0) 109bool(false) 110int(0) 111int(0) 112bool(false) 113int(0) 114int(1) 115bool(false) 116int(0) 117int(513) 118bool(false) 119int(0) 120int(1113) 121bool(false) 122int(512) 123-- File opened in mode r+b -- 124int(-1) 125int(0) 126bool(false) 127int(0) 128int(0) 129bool(false) 130int(0) 131int(1) 132bool(false) 133int(0) 134int(513) 135bool(false) 136int(0) 137int(1113) 138bool(false) 139int(512) 140-- File opened in mode r+t -- 141int(-1) 142int(0) 143bool(false) 144int(0) 145int(0) 146bool(false) 147int(0) 148int(1) 149bool(false) 150int(0) 151int(513) 152bool(false) 153int(0) 154int(1113) 155bool(false) 156int(512) 157-- File opened in mode a -- 158int(-1) 159int(0) 160bool(false) 161int(0) 162int(0) 163bool(false) 164int(0) 165int(1) 166bool(false) 167int(0) 168int(513) 169bool(false) 170int(0) 171int(1113) 172bool(false) 173int(512) 174-- File opened in mode ab -- 175int(-1) 176int(0) 177bool(false) 178int(0) 179int(0) 180bool(false) 181int(0) 182int(1) 183bool(false) 184int(0) 185int(513) 186bool(false) 187int(0) 188int(1113) 189bool(false) 190int(512) 191-- File opened in mode at -- 192int(-1) 193int(0) 194bool(false) 195int(0) 196int(0) 197bool(false) 198int(0) 199int(1) 200bool(false) 201int(0) 202int(513) 203bool(false) 204int(0) 205int(1113) 206bool(false) 207int(512) 208-- File opened in mode a+ -- 209int(-1) 210int(0) 211bool(false) 212int(0) 213int(0) 214bool(false) 215int(0) 216int(1) 217bool(false) 218int(0) 219int(513) 220bool(false) 221int(0) 222int(1113) 223bool(false) 224int(512) 225-- File opened in mode a+b -- 226int(-1) 227int(0) 228bool(false) 229int(0) 230int(0) 231bool(false) 232int(0) 233int(1) 234bool(false) 235int(0) 236int(513) 237bool(false) 238int(0) 239int(1113) 240bool(false) 241int(512) 242-- File opened in mode a+t -- 243int(-1) 244int(0) 245bool(false) 246int(0) 247int(0) 248bool(false) 249int(0) 250int(1) 251bool(false) 252int(0) 253int(513) 254bool(false) 255int(0) 256int(1113) 257bool(false) 258int(512) 259-- File having data of type alphanumeric -- 260-- File opened in mode r -- 261int(-1) 262int(0) 263bool(false) 264int(0) 265int(0) 266bool(false) 267int(0) 268int(1) 269bool(false) 270int(0) 271int(513) 272bool(false) 273int(0) 274int(1113) 275bool(false) 276int(512) 277-- File opened in mode rb -- 278int(-1) 279int(0) 280bool(false) 281int(0) 282int(0) 283bool(false) 284int(0) 285int(1) 286bool(false) 287int(0) 288int(513) 289bool(false) 290int(0) 291int(1113) 292bool(false) 293int(512) 294-- File opened in mode rt -- 295int(-1) 296int(0) 297bool(false) 298int(0) 299int(0) 300bool(false) 301int(0) 302int(1) 303bool(false) 304int(0) 305int(513) 306bool(false) 307int(0) 308int(1113) 309bool(false) 310int(512) 311-- File opened in mode r+ -- 312int(-1) 313int(0) 314bool(false) 315int(0) 316int(0) 317bool(false) 318int(0) 319int(1) 320bool(false) 321int(0) 322int(513) 323bool(false) 324int(0) 325int(1113) 326bool(false) 327int(512) 328-- File opened in mode r+b -- 329int(-1) 330int(0) 331bool(false) 332int(0) 333int(0) 334bool(false) 335int(0) 336int(1) 337bool(false) 338int(0) 339int(513) 340bool(false) 341int(0) 342int(1113) 343bool(false) 344int(512) 345-- File opened in mode r+t -- 346int(-1) 347int(0) 348bool(false) 349int(0) 350int(0) 351bool(false) 352int(0) 353int(1) 354bool(false) 355int(0) 356int(513) 357bool(false) 358int(0) 359int(1113) 360bool(false) 361int(512) 362-- File opened in mode a -- 363int(-1) 364int(0) 365bool(false) 366int(0) 367int(0) 368bool(false) 369int(0) 370int(1) 371bool(false) 372int(0) 373int(513) 374bool(false) 375int(0) 376int(1113) 377bool(false) 378int(512) 379-- File opened in mode ab -- 380int(-1) 381int(0) 382bool(false) 383int(0) 384int(0) 385bool(false) 386int(0) 387int(1) 388bool(false) 389int(0) 390int(513) 391bool(false) 392int(0) 393int(1113) 394bool(false) 395int(512) 396-- File opened in mode at -- 397int(-1) 398int(0) 399bool(false) 400int(0) 401int(0) 402bool(false) 403int(0) 404int(1) 405bool(false) 406int(0) 407int(513) 408bool(false) 409int(0) 410int(1113) 411bool(false) 412int(512) 413-- File opened in mode a+ -- 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(0) 427int(1113) 428bool(false) 429int(512) 430-- File opened in mode a+b -- 431int(-1) 432int(0) 433bool(false) 434int(0) 435int(0) 436bool(false) 437int(0) 438int(1) 439bool(false) 440int(0) 441int(513) 442bool(false) 443int(0) 444int(1113) 445bool(false) 446int(512) 447-- File opened in mode a+t -- 448int(-1) 449int(0) 450bool(false) 451int(0) 452int(0) 453bool(false) 454int(0) 455int(1) 456bool(false) 457int(0) 458int(513) 459bool(false) 460int(0) 461int(1113) 462bool(false) 463int(512) 464Done 465