GetFoldersAndFiles.php
上传用户:wlfwy2004
上传日期:2016-12-12
资源大小:33978k
文件大小:4k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. <?php 
  2. /*
  3.  * FCKeditor - The text editor for internet
  4.  * Copyright (C) 2003-2005 Frederico Caldeira Knabben
  5.  * 
  6.  * Licensed under the terms of the GNU Lesser General Public License:
  7.  *  http://www.opensource.org/licenses/lgpl-license.php
  8.  * 
  9.  * For further information visit:
  10.  *  http://www.fckeditor.net/
  11.  * 
  12.  * File Name: GetFoldersAndFiles.php
  13.  *  Implements the GetFoldersAndFiles command, to list
  14.  *  files and folders in the current directory.
  15.  *  Output is in XML
  16.  * 
  17.  * File Authors:
  18.  *  Grant French (grant@mcpuk.net)
  19.  */
  20. class GetFoldersAndFiles {
  21. var $fckphp_config;
  22. var $type;
  23. var $cwd;
  24. var $actual_cwd;
  25. function GetFoldersAndFiles($fckphp_config,$type,$cwd) {
  26. $this->fckphp_config=$fckphp_config;
  27. $this->type=$type;
  28. $this->raw_cwd=$cwd;
  29. $this->actual_cwd=str_replace("//","/",($fckphp_config['UserFilesPath']."/$type/".$this->raw_cwd));
  30. $this->real_cwd=str_replace("//","/",($this->fckphp_config['basedir']."/".$this->actual_cwd));
  31. }
  32. function run() {
  33. header ("Content-Type: application/xml; charset=utf-8");
  34. echo "<?xml version="1.0" encoding="utf-8" ?>n";
  35. ?>
  36. <!DOCTYPE Connector [
  37. <?php include "dtd/iso-lat1.ent";?>
  38. <!ELEMENT Connector (CurrentFolder,Folders,Files)>
  39. <!ATTLIST Connector command CDATA "noname">
  40. <!ATTLIST Connector resourceType CDATA "0">
  41. <!ELEMENT CurrentFolder (#PCDATA)>
  42. <!ATTLIST CurrentFolder path CDATA "noname">
  43. <!ATTLIST CurrentFolder url CDATA "0">
  44. <!ELEMENT Folders (#PCDATA)>
  45. <!ELEMENT Folder (#PCDATA)>
  46. <!ATTLIST Folder name CDATA "noname_dir">
  47. <!ELEMENT Files (#PCDATA)>
  48. <!ELEMENT File (#PCDATA)>
  49. <!ATTLIST File name CDATA "noname_file">
  50. <!ATTLIST File size CDATA "0">
  51. ] >
  52. <Connector command="GetFoldersAndFiles" resourceType="<?php echo $this->type; ?>">
  53. <CurrentFolder path="<?php echo $this->raw_cwd; ?>" url="<?php echo $this->fckphp_config['urlprefix'] . $this->actual_cwd; ?>" />
  54. <Folders>
  55. <?php
  56. $files=array();
  57. if ($dh=opendir($this->real_cwd)) {
  58. while (($filename=readdir($dh))!==false) {
  59. if (($filename!=".")&&($filename!="..")) {
  60. if (is_dir($this->real_cwd."/$filename")) {
  61. //check if$fckphp_configured not to show this folder
  62. $hide=false;
  63. for($i=0;$i<sizeof($this->fckphp_config['ResourceAreas'][$this->type]['HideFolders']);$i++) 
  64. $hide=(ereg($this->fckphp_config['ResourceAreas'][$this->type]['HideFolders'][$i],$filename)?true:$hide);
  65. if (!$hide) echo "tt<Folder name="$filename" />n";
  66. } else {
  67. array_push($files,$filename);
  68. }
  69. }
  70. }
  71. closedir($dh); 
  72. }
  73. echo "t</Folders>n";
  74. echo "t<Files>n";
  75. for ($i=0;$i<sizeof($files);$i++) {
  76. $lastdot=strrpos($files[$i],".");
  77. $ext=(($lastdot!==false)?(substr($files[$i],$lastdot+1)):"");
  78. if (in_array(strtolower($ext),$this->fckphp_config['ResourceAreas'][$this->type]['AllowedExtensions'])) {
  79. //check if$fckphp_configured not to show this file
  80. $editable=$hide=false;
  81. for($j=0;$j<sizeof($this->fckphp_config['ResourceAreas'][$this->type]['HideFiles']);$j++) 
  82. $hide=(ereg($this->fckphp_config['ResourceAreas'][$this->type]['HideFiles'][$j],$files[$i])?true:$hide);
  83. if (!$hide) {
  84. if ($this->fckphp_config['ResourceAreas'][$this->type]['AllowImageEditing']) 
  85. $editable=$this->isImageEditable($this->real_cwd."/".$files[$i]);
  86. echo "tt<File name="".htmlentities($files[$i])."" size="".ceil(filesize($this->real_cwd."/".$files[$i])/1024)."" editable="" . ( $editable?"1":"0" ) . "" />n";
  87. }
  88. }
  89. }
  90. echo "t</Files>n"; 
  91. echo "</Connector>n";
  92. }
  93. function isImageEditable($file) {
  94. $fh=fopen($file,"r");
  95. if ($fh) {
  96. $start4=fread($fh,4);
  97. fclose($fh);
  98. $start3=substr($start4,0,3);
  99. if ($start4=="x89PNG") { //PNG
  100. return (function_exists("imagecreatefrompng") && function_exists("imagepng"));
  101. } elseif ($start3=="GIF") { //GIF
  102. return (function_exists("imagecreatefromgif") && function_exists("imagegif"));
  103. } elseif ($start3=="xFFxD8xFF") { //JPEG
  104. return (function_exists("imagecreatefromjpeg")&& function_exists("imagejpeg"));
  105. } elseif ($start4=="hsi1") { //JPEG
  106. return (function_exists("imagecreatefromjpeg")&& function_exists("imagejpeg"));
  107. } else {
  108. return false;
  109. }
  110. } else {
  111. return false;
  112. }
  113. }
  114. }
  115. ?>