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