/htdocs/lib/contrib/class.files.php

https://gitlab.com/alidz1982/pookmail · PHP · 165 lines · 94 code · 15 blank · 56 comment · 9 complexity · fa6f77b7166d3b70e518702420d701b1 MD5 · raw file

  1. <?php
  2. // ---------------------------------------------------------------------------
  3. // Image Validator by Alfred Reinold Baudisch<alfred_baudisch@hotmail.com>
  4. // Copyright © 2003, 2004 AuriumSoft - www.auriumsoft.com.br
  5. // ---------------------------------------------------------------------------
  6. // This program is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU General Public License as published by
  8. // the Free Software Foundation; either version 2 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // This program is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU General Public License
  17. // along with this program; if not, write to the Free Software
  18. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. // ---------------------------------------------------------------------------
  20. /**
  21. * Common functions to file manipulation
  22. *
  23. * @author Alfred Reinold Baudisch<alfred_baudisch@hotmail.com>
  24. * @since Jan 19, 2004
  25. * @package Files
  26. */
  27. class files
  28. {
  29. /**
  30. * GetFileList
  31. *
  32. * Creates an array with a list of files of a given dir.
  33. * You can choice specific types of files or all files of the dir.
  34. *
  35. * @param string $directory The dir name that have the files you want
  36. * to create the filelist
  37. * @param mixed $type File types that will be added to the list. That can be:
  38. * images, pages, videos or docs. Default is all files of the dir.
  39. * @param boolean $print_list For debugging
  40. * @return array
  41. * @access public
  42. * @since Nov 11, 2003
  43. */
  44. function get_file_list($directory, $type = "img_creation", $print_list = false)
  45. {
  46. // Checks the dir
  47. if(!is_dir($directory))
  48. {
  49. $this->_error("Invalid Directory: " . $diretorio, E_USER_ERROR);
  50. }
  51. // File types regex
  52. Switch($type)
  53. {
  54. Case "img_creation":
  55. $types_regex = "jpeg|jpg|png";
  56. break;
  57. Case "img":
  58. $types_regex = "gif|jpeg|jpg|png|bmp";
  59. break;
  60. Case "pag":
  61. $types_regex = "txt|htm|html|php|asp|aspx";
  62. break;
  63. Case "vid":
  64. $types_regex = "avi|swf|mpg|mpeg|wmv|asx|mov";
  65. break;
  66. Case "doc":
  67. $types_regex = "txt|doc|rtf|xsl";
  68. break;
  69. Default:
  70. $types_regex = false;
  71. }
  72. // Open dir handle
  73. if(!$dir_handle = @opendir($directory))
  74. {
  75. $this->_error("I couldn't open the dir: " . $directory, E_USER_ERROR);
  76. }
  77. // Initilization of the list array
  78. $file_list = array();
  79. // Starts dir navigation
  80. while (false !== ($file = @readdir($dir_handle)))
  81. {
  82. if ($file == "." || $file == "..")
  83. {
  84. continue;
  85. }
  86. // The list will be generate with specific types, according to the regex
  87. if($types_regex)
  88. {
  89. if(eregi( "\.(" . $types_regex . ")$", $file))
  90. {
  91. $file_list[] = $file;
  92. }
  93. }
  94. // The list will be generate with all dir's files
  95. else
  96. {
  97. // Add only files to the list
  98. if(is_file($directory . $file))
  99. {
  100. $file_list[] = $file;
  101. }
  102. }
  103. }
  104. // Close dir handle
  105. @closedir($dir_handle);
  106. // Has no files in the dir
  107. if(!sizeof($file_list))
  108. {
  109. $this->_error("The directory: " . $directory . " is empty!", E_USER_NOTICE);
  110. }
  111. // If debugging...
  112. if($print_list)
  113. {
  114. echo "<pre>";
  115. print_r($file_list);
  116. echo "</pre>";
  117. }
  118. // Returns file list
  119. return $file_list;
  120. }
  121. /**
  122. * Prints errors messages
  123. *
  124. * @param string $mensagem The error message
  125. * @param integer $tipo Error type
  126. * @access private
  127. * @since Jan 19, 2004
  128. */
  129. function _error($mensagem, $tipo)
  130. {
  131. if($tipo == E_USER_ERROR)
  132. {
  133. $topo = "Error!";
  134. }
  135. else
  136. {
  137. $topo = "Notification";
  138. }
  139. echo "<span style=\"background-color: #FFD7D7\"><font face=verdana size=2><font color=red><b>" . $topo . "</b></font>: " . $mensagem . "</font></span><br><br>";
  140. if($tipo == E_USER_ERROR)
  141. {
  142. exit;
  143. }
  144. }
  145. }
  146. ?>