imageManager.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Created by JetBrains PhpStorm.
  4. * User: taoqili
  5. * Date: 12-1-16
  6. * Time: 上午11:44
  7. * To change this template use File | Settings | File Templates.
  8. */
  9. header("Content-Type: text/html; charset=utf-8");
  10. error_reporting( E_ERROR | E_WARNING );
  11. //需要遍历的目录列表,最好使用缩略图地址,否则当网速慢时可能会造成严重的延时
  12. $paths = array('upload/','upload1/');
  13. $action = htmlspecialchars( $_POST[ "action" ] );
  14. if ( $action == "get" ) {
  15. $files = array();
  16. foreach ( $paths as $path){
  17. $tmp = getfiles( $path );
  18. if($tmp){
  19. $files = array_merge($files,$tmp);
  20. }
  21. }
  22. if ( !count($files) ) return;
  23. rsort($files,SORT_STRING);
  24. $str = "";
  25. foreach ( $files as $file ) {
  26. $str .= $file . "ue_separate_ue";
  27. }
  28. echo $str;
  29. }
  30. /**
  31. * 遍历获取目录下的指定类型的文件
  32. * @param $path
  33. * @param array $files
  34. * @return array
  35. */
  36. function getfiles( $path , &$files = array() )
  37. {
  38. if ( !is_dir( $path ) ) return null;
  39. $handle = opendir( $path );
  40. while ( false !== ( $file = readdir( $handle ) ) ) {
  41. if ( $file != '.' && $file != '..' ) {
  42. $path2 = $path . '/' . $file;
  43. if ( is_dir( $path2 ) ) {
  44. getfiles( $path2 , $files );
  45. } else {
  46. if ( preg_match( "/\.(gif|jpeg|jpg|png|bmp)$/i" , $file ) ) {
  47. $files[] = $path2;
  48. }
  49. }
  50. }
  51. }
  52. return $files;
  53. }