readfile_basic.phpt 13 KB

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