readfile_variation9.phpt 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. --TEST--
  2. Test readfile() function : variation - variable types of path
  3. --CREDITS--
  4. Dave Kelsey <d_kelsey@uk.ibm.com>
  5. --FILE--
  6. <?php
  7. echo "*** Testing readfile() : variation ***\n";
  8. $mainDir = "readfileVar8";
  9. $subDir = "readfileVar8Sub";
  10. $absMainDir = __DIR__."/".$mainDir;
  11. mkdir($absMainDir);
  12. $absSubDir = $absMainDir."/".$subDir;
  13. mkdir($absSubDir);
  14. $theFile = "fileToRead.tmp";
  15. $absFile = $absSubDir.'/'.$theFile;
  16. // create the file
  17. $h = fopen($absFile,"w");
  18. fwrite($h, "The File Contents");
  19. fclose($h);
  20. $old_dir_path = getcwd();
  21. chdir(__DIR__);
  22. $allDirs = array(
  23. // absolute paths
  24. "$absSubDir/",
  25. "$absSubDir/../".$subDir,
  26. "$absSubDir//.././".$subDir,
  27. "$absSubDir/../../".$mainDir."/./".$subDir,
  28. "$absSubDir/..///".$subDir."//..//../".$subDir,
  29. "$absSubDir/BADDIR",
  30. // relative paths
  31. $mainDir."/".$subDir,
  32. $mainDir."//".$subDir,
  33. $mainDir."///".$subDir,
  34. "./".$mainDir."/../".$mainDir."/".$subDir,
  35. "BADDIR",
  36. );
  37. for($i = 0; $i<count($allDirs); $i++) {
  38. $j = $i+1;
  39. $dir = $allDirs[$i];
  40. echo "\n-- Iteration $j --\n";
  41. $ok = readfile($dir.'/'.$theFile);
  42. if ($ok === 1) {
  43. echo "\n";
  44. }
  45. }
  46. unlink($absFile);
  47. chdir($old_dir_path);
  48. rmdir($absSubDir);
  49. rmdir($absMainDir);
  50. echo "\n*** Done ***\n";
  51. ?>
  52. --EXPECTF--
  53. *** Testing readfile() : variation ***
  54. -- Iteration 1 --
  55. The File Contents
  56. -- Iteration 2 --
  57. The File Contents
  58. -- Iteration 3 --
  59. The File Contents
  60. -- Iteration 4 --
  61. The File Contents
  62. -- Iteration 5 --
  63. Warning: readfile(%sreadfileVar8Sub/..///readfileVar8Sub//..//../readfileVar8Sub/fileToRead.tmp): Failed to open stream: No such file or directory in %s on line %d
  64. -- Iteration 6 --
  65. Warning: readfile(%sreadfileVar8Sub/BADDIR/fileToRead.tmp): Failed to open stream: No such file or directory in %s on line %d
  66. -- Iteration 7 --
  67. The File Contents
  68. -- Iteration 8 --
  69. The File Contents
  70. -- Iteration 9 --
  71. The File Contents
  72. -- Iteration 10 --
  73. The File Contents
  74. -- Iteration 11 --
  75. Warning: readfile(BADDIR/fileToRead.tmp): Failed to open stream: No such file or directory in %s on line %d
  76. *** Done ***