3
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
4
* Copyright (C) 2003-2007 Frederico Caldeira Knabben
8
* Licensed under the terms of any of the following licenses at your
11
* - GNU General Public License Version 2 or later (the "GPL")
12
* http://www.gnu.org/licenses/gpl.html
14
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
15
* http://www.gnu.org/licenses/lgpl.html
17
* - Mozilla Public License Version 1.1 or later (the "MPL")
18
* http://www.mozilla.org/MPL/MPL-1.1.html
22
* This is the "File Uploader" for Lasso.
25
/*.....................................................................
26
Include global configuration. See config.lasso for details.
28
include('config.lasso');
31
/*.....................................................................
32
Convert query string parameters to variables and initialize output.
35
'Type' = action_param('Type'),
36
'CurrentFolder' = action_param('CurrentFolder'),
37
'ServerPath' = action_param('ServerPath'),
39
'NewFileName' = string,
40
'OrigFilePath' = string,
41
'NewFilePath' = string,
46
$Type == '' ? $Type = 'File';
49
/*.....................................................................
50
Calculate the path to the current folder.
52
$ServerPath == '' ? $ServerPath = $config->find('UserFilesPath');
54
var('currentFolderURL' = $ServerPath
55
+ $config->find('Subdirectories')->find(action_param('Type'))
56
+ action_param('CurrentFolder')
60
/*.....................................................................
61
Custom tag sets the HTML response.
68
-required='errorNumber',
74
-optional='customMsg',
76
-description='Sets the HTML response for the FCKEditor Quick Upload feature.'
79
<script type="text/javascript">
80
window.parent.OnUploadCompleted(' + #errorNumber + ',"'
81
+ string_replace(#fileUrl, -find='"', -replace='\\"') + '","'
82
+ string_replace(#fileName, -find='"', -replace='\\"') + '","'
83
+ string_replace(#customMsg, -find='"', -replace='\\"') + '");
89
if($config->find('Enabled'));
90
/*.................................................................
91
Process an uploaded file.
94
/*.............................................................
95
Was a file actually uploaded?
97
file_uploads->size ? $NewFile = file_uploads->get(1) | $errorNumber = 202;
99
if($errorNumber == 0);
100
/*.........................................................
101
Split the file's extension from the filename in order
102
to follow the API's naming convention for duplicate
103
files. (Test.txt, Test(1).txt, Test(2).txt, etc.)
105
$NewFileName = $NewFile->find('OrigName');
106
$OrigFilePath = $currentFolderURL + $NewFileName;
107
$NewFilePath = $OrigFilePath;
108
local('fileExtension') = '.' + $NewFile->find('OrigExtension');
109
local('shortFileName') = $NewFileName->removetrailing(#fileExtension)&;
112
/*.........................................................
113
Make sure the file extension is allowed.
116
if($config->find('DeniedExtensions')->find($Type) >> $NewFile->find('OrigExtension'));
119
/*.....................................................
120
Rename the target path until it is unique.
122
while(file_exists($NewFilePath));
123
$NewFileName = #shortFileName + '(' + loop_count + ')' + #fileExtension;
124
$NewFilePath = $currentFolderURL + $NewFileName;
128
/*.....................................................
129
Copy the uploaded file to its final location.
131
file_copy($NewFile->find('path'), $NewFilePath);
134
/*.....................................................
135
Set the error code for the response.
137
select(file_currenterror( -errorcode));
139
$OrigFilePath != $NewFilePath ? $errorNumber = 201;
148
$customMsg = 'This file uploader is disabled. Please check the "editor/filemanager/upload/lasso/config.lasso" file.';
152
-errorNumber=$errorNumber,
153
-fileUrl=$NewFilePath,
154
-fileName=$NewFileName,
155
-customMsg=$customMsg