Home  >  Article  >  Backend Development  >  PHP code example for browsing file contents in a directory

PHP code example for browsing file contents in a directory

WBOY
WBOYOriginal
2016-07-25 08:59:06724browse
  1. /**
  2. * Browse files in the directory
  3. * edit bbs.it-home.org
  4. */
  5. $dir = dirname(__FILE__);
  6. $open_dir = opendir($dir);
  7. echo "";
  8. echo "
  9. ";
  10. while ($file = readdir($open_dir)) {
  11. if ($file!= "." && $file != "..") {
  12. echo "< tr>
  13. ";
  14. echo "
  15. ";
  16. echo "
  17. ";
  18. echo "
  19. ";
  20. }
  21. }
  22. echo "
  23. File nameSizeTypeModification date< ;/th>
    " . $file . " " . filesize($file) . " " . filetype($file) . " " . filemtime($file) . "
    ";
  24. ?>
Copy code

Example 2,

  1. Browse directory_bbs.it-home.org
  2. // Use the table to browse the structure of the directory
  3. print("n");
  4. // Create the header of the table
  5. print("
  6. print("n");
  7. print("
  8. n");
  9. print("< /font>
  10. n");
  11. $myDirectory = opendir("."); // Create a handle to the operating directory
  12. // Read each sub-item in the directory
  13. while($entryName = readdir( $myDirectory))
  14. {
  15. print("
  16. ");
  17. print("
  18. ");
  19. print("
  20. ");
  21. print("
  22. n");
  23. }
  24. closedir($myDirectory); // Close the directory
  25. print("
  26. File nameFile size
    $entryName") ;
  27. print(filesize($entryName));
  28. print("
  29. n");
  30. ?>
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn