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