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