upload.lasso
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:6k
源码类别:

OA系统

开发平台:

C#

  1. [//lasso
  2. /*
  3.  * FCKeditor - The text editor for internet
  4.  * Copyright (C) 2003-2006 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: upload.php
  13.  *  This is the "File Uploader" for Lasso.
  14.  * 
  15.  * File Authors:
  16.  *  Jason Huck (jason.huck@corefive.com)
  17.  */
  18.     /*.....................................................................     
  19.     Include global configuration. See config.lasso for details.                                                                           
  20.     */                                                                          
  21. include('config.lasso');
  22.     /*.....................................................................     
  23.     Convert query string parameters to variables and initialize output.                                                                           
  24.     */                                                                          
  25. var(
  26. 'Type' = action_param('Type'),
  27. 'CurrentFolder' = action_param('CurrentFolder'),
  28. 'ServerPath' = action_param('ServerPath'),
  29. 'NewFile' = null,
  30. 'NewFileName' = string,
  31. 'OrigFilePath' = string,
  32. 'NewFilePath' = string,
  33. 'errorNumber' = 0,
  34. 'customMsg' = ''
  35. );
  36. $Type == '' ? $Type = 'File';
  37.     /*.....................................................................     
  38.     Calculate the path to the current folder.                                                                           
  39.     */                                                                          
  40. $ServerPath == '' ? $ServerPath = $config->find('UserFilesPath');
  41. var('currentFolderURL' = $ServerPath 
  42. + $config->find('Subdirectories')->find(action_param('Type'))
  43. + action_param('CurrentFolder')
  44. );
  45. /*.....................................................................    
  46. Custom tag sets the HTML response.                                                               
  47. */
  48. define_tag(
  49. 'sendresults',
  50. -namespace='fck_',
  51. -priority='replace',
  52. -required='errorNumber',
  53. -type='integer',
  54. -optional='fileUrl',
  55. -type='string',
  56. -optional='fileName',
  57. -type='string',
  58. -optional='customMsg',
  59. -type='string',
  60. -description='Sets the HTML response for the FCKEditor Quick Upload feature.'
  61. );
  62. $__html_reply__ = '
  63. <script type="text/javascript">
  64. window.parent.OnUploadCompleted(' + #errorNumber + ',"' 
  65. + string_replace(#fileUrl, -find='"', -replace='\"') + '","' 
  66. + string_replace(#fileName, -find='"', -replace='\"') + '","' 
  67. + string_replace(#customMsg, -find='"', -replace='\"') + '");
  68. </script>
  69. ';
  70. /define_tag;
  71. if($config->find('Enabled'));
  72. /*.................................................................     
  73. Process an uploaded file.                                                                        
  74. */                                                                          
  75. inline($connection);
  76. /*.............................................................     
  77. Was a file actually uploaded?                                                              
  78. */                                                              
  79. file_uploads->size ? $NewFile = file_uploads->get(1) | $errorNumber = 202;
  80. if($errorNumber == 0);
  81. /*.........................................................     
  82. Split the file's extension from the filename in order
  83. to follow the API's naming convention for duplicate
  84. files. (Test.txt, Test(1).txt, Test(2).txt, etc.)                                                          
  85. */                                                          
  86. $NewFileName = $NewFile->find('OrigName');
  87. $OrigFilePath = $currentFolderURL + $NewFileName;
  88. $NewFilePath = $OrigFilePath;
  89. local('fileExtension') = '.' + $NewFile->find('OrigExtension');
  90. local('shortFileName') = $NewFileName->removetrailing(#fileExtension)&;
  91. /*.........................................................     
  92. Make sure the file extension is allowed.                                                          
  93. */ 
  94. if($config->find('DeniedExtensions')->find($Type) >> $NewFile->find('OrigExtension'));
  95. $errorNumber = 202;
  96. else;
  97. /*.....................................................     
  98. Rename the target path until it is unique.                                                    
  99. */                                                      
  100. while(file_exists($NewFilePath));
  101. $NewFileName = #shortFileName + '(' + loop_count + ')' + #fileExtension;
  102. $NewFilePath = $currentFolderURL + $NewFileName;
  103. /while;
  104. /*.....................................................     
  105. Copy the uploaded file to its final location.                                                     
  106. */                                                      
  107. file_copy($NewFile->find('path'), $NewFilePath);
  108. /*.....................................................    
  109. Set the error code for the response.                                          
  110. */                                                      
  111. select(file_currenterror( -errorcode));
  112. case(0);
  113. $OrigFilePath != $NewFilePath ? $errorNumber = 201;
  114. case;
  115. $errorNumber = 202;
  116. /select;
  117. /if;
  118. /if;
  119. /inline;
  120. else;
  121. $errorNumber = 1;
  122. $customMsg = 'This file uploader is disabled. Please check the "editor/filemanager/upload/lasso/config.lasso" file.';
  123. /if;
  124. fck_sendresults(
  125. -errorNumber=$errorNumber,
  126. -fileUrl=$NewFilePath,
  127. -fileName=$NewFileName,
  128. -customMsg=$customMsg
  129. );
  130. ]