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