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