[ Index ] |
|
Code source de FCKeditor 2.4 |
1 <!--- 2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net 3 * Copyright (C) 2003-2007 Frederico Caldeira Knabben 4 * 5 * == BEGIN LICENSE == 6 * 7 * Licensed under the terms of any of the following licenses at your 8 * choice: 9 * 10 * - GNU General Public License Version 2 or later (the "GPL") 11 * http://www.gnu.org/licenses/gpl.html 12 * 13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 14 * http://www.gnu.org/licenses/lgpl.html 15 * 16 * - Mozilla Public License Version 1.1 or later (the "MPL") 17 * http://www.mozilla.org/MPL/MPL-1.1.html 18 * 19 * == END LICENSE == 20 * 21 * File Name: upload.cfm 22 * This is the "File Uploader" for ColdFusion. 23 * Based on connector.cfm by Mark Woods (mark@thickpaddy.com) 24 * 25 * File Authors: 26 * Wim Lemmens (didgiman@gmail.com) 27 ---> 28 29 <cfinclude template="config.cfm"> 30 31 <cfparam name="url.type" default="File"> 32 33 <cffunction name="SendResults"> 34 <cfargument name="errorNumber" type="numeric" required="yes"> 35 <cfargument name="fileUrl" type="string" required="no" default=""> 36 <cfargument name="fileName" type="string" required="no" default=""> 37 <cfargument name="customMsg" type="string" required="no" default=""> 38 39 <cfoutput> 40 <script type="text/javascript"> 41 window.parent.OnUploadCompleted(#errorNumber#, "#JSStringFormat(fileUrl)#", "#JSStringFormat(fileName)#", "#JSStringFormat(customMsg)#"); 42 </script> 43 </cfoutput> 44 45 <cfabort><!--- Result sent, stop processing this page ---> 46 </cffunction> 47 48 <cfif NOT config.enabled> 49 <cfset SendResults(1, '', '', 'This file uploader is disabled. Please check the "editor/filemanager/upload/cfm/config.cfm" file')> 50 <cfelse> 51 <cfscript> 52 53 userFilesPath = config.userFilesPath; 54 lAllowedExtensions = config.allowedExtensions[url.type]; 55 lDeniedExtensions = config.deniedExtensions[url.type]; 56 customMsg = ''; // Can be overwritten. The last value will be sent with the result 57 58 // make sure the user files path is correctly formatted 59 userFilesPath = replace(userFilesPath, "\", "/", "ALL"); 60 userFilesPath = replace(userFilesPath, '//', '/', 'ALL'); 61 if ( right(userFilesPath,1) NEQ "/" ) { 62 userFilesPath = userFilesPath & "/"; 63 } 64 if ( left(userFilesPath,1) NEQ "/" ) { 65 userFilesPath = "/" & userFilesPath; 66 } 67 68 if (find("/",getBaseTemplatePath())) { 69 fs = "/"; 70 } else { 71 fs = "\"; 72 } 73 74 // Get the base physical path to the web root for this application. The code to determine the path automatically assumes that 75 // the "FCKeditor" directory in the http request path is directly off the web root for the application and that it's not a 76 // virtual directory or a symbolic link / junction. Use the serverPath config setting to force a physical path if necessary. 77 if ( len(config.serverPath) ) { 78 serverPath = config.serverPath; 79 } else { 80 serverPath = replaceNoCase(getBaseTemplatePath(),replace(cgi.script_name,"/",fs,"all"),""); 81 } 82 83 // map the user files path to a physical directory 84 userFilesServerPath = serverPath & replace(userFilesPath,"/",fs,"all"); 85 </cfscript> 86 87 <cfset fileName = ""> 88 <cfset fileExt = ""> 89 90 <cftry> 91 92 <!--- we need to know the physical path to the current folder for all commands ---> 93 <cfset currentFolderPath = userFilesServerPath & url.type & fs> 94 95 <!--- TODO: upload to a temp directory and move file if extension is allowed ---> 96 97 <!--- first upload the file with an unique filename ---> 98 <cffile action="upload" 99 fileField="NewFile" 100 destination="#currentFolderPath#" 101 nameConflict="makeunique" 102 mode="644" 103 attributes="normal"> 104 105 <cfif (Len(lAllowedExtensions) AND NOT listFindNoCase(lAllowedExtensions, cffile.ServerFileExt)) 106 OR (Len(lDeniedExtensions) AND listFindNoCase(lDeniedExtensions, cffile.ServerFileExt))> 107 108 <!--- Extension of the uploaded file is not allowed ---> 109 <cfset errorNumber = "202"> 110 <cffile action="delete" file="#cffile.ServerDirectory##fs##cffile.ServerFile#"> 111 112 <cfelse> 113 114 <cfscript> 115 errorNumber = 0; 116 fileName = cffile.ClientFileName; 117 fileExt = cffile.ServerFileExt; 118 119 // munge filename for html download. Only a-z, 0-9, _, - and . are allowed 120 if( reFind("[^A-Za-z0-9_\-\.]", fileName) ) { 121 fileName = reReplace(fileName, "[^A-Za-z0-9\-\.]", "_", "ALL"); 122 fileName = reReplace(fileName, "_{2,}", "_", "ALL"); 123 fileName = reReplace(fileName, "([^_]+)_+$", "\1", "ALL"); 124 fileName = reReplace(fileName, "$_([^_]+)$", "\1", "ALL"); 125 } 126 127 // When the original filename already exists, add numbers (0), (1), (2), ... at the end of the filename. 128 if( compare( cffile.ServerFileName, fileName ) ) { 129 counter = 0; 130 tmpFileName = fileName; 131 while( fileExists("#currentFolderPath##fileName#.#fileExt#") ) { 132 counter = counter + 1; 133 fileName = tmpFileName & '(#counter#)'; 134 } 135 } 136 </cfscript> 137 138 <!--- Rename the uploaded file, if neccessary ---> 139 <cfif compare(cffile.ServerFileName,fileName)> 140 141 <cfset errorNumber = "201"> 142 <cffile 143 action="rename" 144 source="#currentFolderPath##cffile.ServerFileName#.#cffile.ServerFileExt#" 145 destination="#currentFolderPath##fileName#.#fileExt#" 146 mode="644" 147 attributes="normal"> 148 149 </cfif> 150 151 </cfif> 152 153 <cfcatch type="Any"> 154 155 <cfset errorNumber = "1"> 156 <cfset customMsg = "An error occured: " & cfcatch.message & " - " & cfcatch.detail> 157 158 </cfcatch> 159 160 </cftry> 161 162 <cfif errorNumber EQ 0> 163 <!--- file was uploaded succesfully ---> 164 <cfset SendResults(errorNumber, '#userFilesPath##url.type#/#fileName#.#fileExt#')> 165 <cfelseif errorNumber EQ 201> 166 <!--- file was changed (201), submit the new filename ---> 167 <cfset SendResults(errorNumber, '#userFilesPath##url.type#/#fileName#.#fileExt#', replace( fileName & "." & fileExt, "'", "\'", "ALL"), customMsg)> 168 <cfelse> 169 <!--- An error occured(202). Submit only the error code and a message (if available). ---> 170 <cfset SendResults(errorNumber, '', '', customMsg)> 171 </cfif> 172 </cfif>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 15:28:05 2007 | par Balluche grâce à PHPXref 0.7 |