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