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

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: RenameFile.php
  13.  *  Implements the DeleteFile command to delete a file
  14.  *  in the current directory. Output is in XML
  15.  * 
  16.  * File Authors:
  17.  *  Grant French (grant@mcpuk.net)
  18.  */
  19. class RenameFile {
  20. var $fckphp_config;
  21. var $type;
  22. var $cwd;
  23. var $actual_cwd;
  24. var $newfolder;
  25. function RenameFile($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. $this->filename=str_replace(array("..","/"),"",$_GET['FileName']);
  32. $this->newname=str_replace(array("..","/"),"",$this->checkName($_GET['NewName']));
  33. }
  34. function checkName($name) {
  35. $newName="";
  36. for ($i=0;$i<strlen($name);$i++) {
  37. if (in_array($name[$i],$this->fckphp_config['FileNameAllowedChars'])) $newName.=$name[$i];
  38. }
  39. return $newName;
  40. }
  41. function run() {
  42. $result1=false;
  43. $result2=true;
  44. if ($this->newname!='') {
  45. if ($this->nameValid($this->newname)) {
  46. //Remove thumbnail if it exists
  47. $result2=true;
  48. $thumb=$this->real_cwd.'/.thumb_'.$this->filename;
  49. if (file_exists($thumb)) $result2=unlink($thumb);
  50. $result1=rename($this->real_cwd.'/'.$this->filename,$this->real_cwd.'/'.$this->newname);
  51. } else {
  52. $result1=false;
  53. }
  54. }
  55. header ("content-type: text/xml");
  56. echo "<?xml version="1.0" encoding="utf-8" ?>n";
  57. ?>
  58. <Connector command="RenameFile" resourceType="<?php echo $this->type; ?>">
  59. <CurrentFolder path="<?php echo $this->raw_cwd; ?>" url="<?php echo $this->actual_cwd; ?>" />
  60. <?php
  61. if ($result1&&$result2) {
  62. $err_no=0;
  63. } else {
  64. $err_no=502;
  65. }
  66. ?>
  67. <Error number="<?php echo "".$err_no; ?>" />
  68. </Connector>
  69. <?php
  70. }
  71. function nameValid($fname) {
  72. $type_config=$this->fckphp_config['ResourceAreas'][$this->type];
  73. $lastdot=strrpos($fname,".");
  74. if ($lastdot!==false) {
  75. $ext=substr($fname,($lastdot+1));
  76. $fname=substr($fname,0,$lastdot);
  77. if (in_array(strtolower($ext),$type_config['AllowedExtensions'])) {
  78. return true;
  79. } else {
  80. return false;
  81. }
  82. }
  83. }
  84. }
  85. ?>