1--TEST--
2Test readfile() function: basic functionality
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6    die('skip.. only on Linux');
7}
8?>
9--FILE--
10<?php
11/* Prototype: int readfile ( string $filename [, bool $use_include_path [, resource $context]] );
12   Description: Outputs a file
13*/
14// common file used
15require(__DIR__ . '/file.inc');
16
17echo "*** Testing readfile() : basic functionality ***\n";
18$file_path = __DIR__;
19$file_prefix = "readfile_basic";  // temp files created with this prefix
20
21// the content that is filled into the temp files as created
22$filetypes = array("numeric", "text", "empty", "alphanumeric", "text_with_new_line");
23// different file modes
24$filemodes = array("w", "wt", "wb", "w+", "w+b", "w+t",
25                   "a", "at", "ab", "a+", "a+b", "a+t",
26                   "x", "xb", "xt", "x+", "x+b", "x+t");
27
28// create file, read the file content, delete file
29foreach($filetypes as $type) {
30  echo "\n-- File filled with content type: $type --\n";
31  foreach($filemodes as $mode) {
32    echo "-- File opened with mode: $mode --\n";
33      if ( strstr($mode, "x") ) {
34         $fp = fopen($file_path."/".$file_prefix."1.tmp", $mode);
35         fill_file($fp, $type, 100);
36         fclose($fp);
37      } else {
38        // creating file in write mode
39        create_files($file_path, 1, $type, 0755, 100, $mode, $file_prefix, 1, "byte");
40      }
41      $count = readfile($file_path."/".$file_prefix."1.tmp");
42      echo "\n";
43      var_dump($count);
44      // delete files created
45      delete_files($file_path, 1, $file_prefix, 1);
46  }
47}
48echo "Done\n";
49?>
50--EXPECT--
51*** Testing readfile() : basic functionality ***
52
53-- File filled with content type: numeric --
54-- File opened with mode: w --
552222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
56int(100)
57-- File opened with mode: wt --
582222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
59int(100)
60-- File opened with mode: wb --
612222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
62int(100)
63-- File opened with mode: w+ --
642222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
65int(100)
66-- File opened with mode: w+b --
672222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
68int(100)
69-- File opened with mode: w+t --
702222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
71int(100)
72-- File opened with mode: a --
732222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
74int(100)
75-- File opened with mode: at --
762222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
77int(100)
78-- File opened with mode: ab --
792222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
80int(100)
81-- File opened with mode: a+ --
822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
83int(100)
84-- File opened with mode: a+b --
852222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
86int(100)
87-- File opened with mode: a+t --
882222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
89int(100)
90-- File opened with mode: x --
912222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
92int(100)
93-- File opened with mode: xb --
942222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
95int(100)
96-- File opened with mode: xt --
972222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
98int(100)
99-- File opened with mode: x+ --
1002222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
101int(100)
102-- File opened with mode: x+b --
1032222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
104int(100)
105-- File opened with mode: x+t --
1062222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
107int(100)
108
109-- File filled with content type: text --
110-- File opened with mode: w --
111text text text text text text text text text text text text text text text text text text text text
112int(100)
113-- File opened with mode: wt --
114text text text text text text text text text text text text text text text text text text text text
115int(100)
116-- File opened with mode: wb --
117text text text text text text text text text text text text text text text text text text text text
118int(100)
119-- File opened with mode: w+ --
120text text text text text text text text text text text text text text text text text text text text
121int(100)
122-- File opened with mode: w+b --
123text text text text text text text text text text text text text text text text text text text text
124int(100)
125-- File opened with mode: w+t --
126text text text text text text text text text text text text text text text text text text text text
127int(100)
128-- File opened with mode: a --
129text text text text text text text text text text text text text text text text text text text text
130int(100)
131-- File opened with mode: at --
132text text text text text text text text text text text text text text text text text text text text
133int(100)
134-- File opened with mode: ab --
135text text text text text text text text text text text text text text text text text text text text
136int(100)
137-- File opened with mode: a+ --
138text text text text text text text text text text text text text text text text text text text text
139int(100)
140-- File opened with mode: a+b --
141text text text text text text text text text text text text text text text text text text text text
142int(100)
143-- File opened with mode: a+t --
144text text text text text text text text text text text text text text text text text text text text
145int(100)
146-- File opened with mode: x --
147text text text text text text text text text text text text text text text text text text text text
148int(100)
149-- File opened with mode: xb --
150text text text text text text text text text text text text text text text text text text text text
151int(100)
152-- File opened with mode: xt --
153text text text text text text text text text text text text text text text text text text text text
154int(100)
155-- File opened with mode: x+ --
156text text text text text text text text text text text text text text text text text text text text
157int(100)
158-- File opened with mode: x+b --
159text text text text text text text text text text text text text text text text text text text text
160int(100)
161-- File opened with mode: x+t --
162text text text text text text text text text text text text text text text text text text text text
163int(100)
164
165-- File filled with content type: empty --
166-- File opened with mode: w --
167
168int(0)
169-- File opened with mode: wt --
170
171int(0)
172-- File opened with mode: wb --
173
174int(0)
175-- File opened with mode: w+ --
176
177int(0)
178-- File opened with mode: w+b --
179
180int(0)
181-- File opened with mode: w+t --
182
183int(0)
184-- File opened with mode: a --
185
186int(0)
187-- File opened with mode: at --
188
189int(0)
190-- File opened with mode: ab --
191
192int(0)
193-- File opened with mode: a+ --
194
195int(0)
196-- File opened with mode: a+b --
197
198int(0)
199-- File opened with mode: a+t --
200
201int(0)
202-- File opened with mode: x --
203
204int(0)
205-- File opened with mode: xb --
206
207int(0)
208-- File opened with mode: xt --
209
210int(0)
211-- File opened with mode: x+ --
212
213int(0)
214-- File opened with mode: x+b --
215
216int(0)
217-- File opened with mode: x+t --
218
219int(0)
220
221-- File filled with content type: alphanumeric --
222-- File opened with mode: w --
223ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12
224int(100)
225-- File opened with mode: wt --
226ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12
227int(100)
228-- File opened with mode: wb --
229ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12
230int(100)
231-- File opened with mode: w+ --
232ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12
233int(100)
234-- File opened with mode: w+b --
235ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12
236int(100)
237-- File opened with mode: w+t --
238ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12
239int(100)
240-- File opened with mode: a --
241ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12
242int(100)
243-- File opened with mode: at --
244ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12
245int(100)
246-- File opened with mode: ab --
247ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12
248int(100)
249-- File opened with mode: a+ --
250ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12
251int(100)
252-- File opened with mode: a+b --
253ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12
254int(100)
255-- File opened with mode: a+t --
256ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12
257int(100)
258-- File opened with mode: x --
259ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12
260int(100)
261-- File opened with mode: xb --
262ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12
263int(100)
264-- File opened with mode: xt --
265ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12
266int(100)
267-- File opened with mode: x+ --
268ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12
269int(100)
270-- File opened with mode: x+b --
271ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12
272int(100)
273-- File opened with mode: x+t --
274ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12
275int(100)
276
277-- File filled with content type: text_with_new_line --
278-- File opened with mode: w --
279line
280line of text
281line
282line of text
283line
284line of text
285line
286line of text
287line
288line of text
289line
290line
291int(100)
292-- File opened with mode: wt --
293line
294line of text
295line
296line of text
297line
298line of text
299line
300line of text
301line
302line of text
303line
304line
305int(100)
306-- File opened with mode: wb --
307line
308line of text
309line
310line of text
311line
312line of text
313line
314line of text
315line
316line of text
317line
318line
319int(100)
320-- File opened with mode: w+ --
321line
322line of text
323line
324line of text
325line
326line of text
327line
328line of text
329line
330line of text
331line
332line
333int(100)
334-- File opened with mode: w+b --
335line
336line of text
337line
338line of text
339line
340line of text
341line
342line of text
343line
344line of text
345line
346line
347int(100)
348-- File opened with mode: w+t --
349line
350line of text
351line
352line of text
353line
354line of text
355line
356line of text
357line
358line of text
359line
360line
361int(100)
362-- File opened with mode: a --
363line
364line of text
365line
366line of text
367line
368line of text
369line
370line of text
371line
372line of text
373line
374line
375int(100)
376-- File opened with mode: at --
377line
378line of text
379line
380line of text
381line
382line of text
383line
384line of text
385line
386line of text
387line
388line
389int(100)
390-- File opened with mode: ab --
391line
392line of text
393line
394line of text
395line
396line of text
397line
398line of text
399line
400line of text
401line
402line
403int(100)
404-- File opened with mode: a+ --
405line
406line of text
407line
408line of text
409line
410line of text
411line
412line of text
413line
414line of text
415line
416line
417int(100)
418-- File opened with mode: a+b --
419line
420line of text
421line
422line of text
423line
424line of text
425line
426line of text
427line
428line of text
429line
430line
431int(100)
432-- File opened with mode: a+t --
433line
434line of text
435line
436line of text
437line
438line of text
439line
440line of text
441line
442line of text
443line
444line
445int(100)
446-- File opened with mode: x --
447line
448line of text
449line
450line of text
451line
452line of text
453line
454line of text
455line
456line of text
457line
458line
459int(100)
460-- File opened with mode: xb --
461line
462line of text
463line
464line of text
465line
466line of text
467line
468line of text
469line
470line of text
471line
472line
473int(100)
474-- File opened with mode: xt --
475line
476line of text
477line
478line of text
479line
480line of text
481line
482line of text
483line
484line of text
485line
486line
487int(100)
488-- File opened with mode: x+ --
489line
490line of text
491line
492line of text
493line
494line of text
495line
496line of text
497line
498line of text
499line
500line
501int(100)
502-- File opened with mode: x+b --
503line
504line of text
505line
506line of text
507line
508line of text
509line
510line of text
511line
512line of text
513line
514line
515int(100)
516-- File opened with mode: x+t --
517line
518line of text
519line
520line of text
521line
522line of text
523line
524line of text
525line
526line of text
527line
528line
529int(100)
530Done
531