1 | diff -Nru FCKeditor_2.6-virgin/editor/filemanager/browser/default/frmupload.html FCKeditor_2.6-patched/editor/filemanager/browser/default/frmupload.html |
---|
2 | --- FCKeditor_2.6-virgin/editor/filemanager/browser/default/frmupload.html 2008-03-20 13:02:52.000000000 +0000 |
---|
3 | +++ FCKeditor_2.6-patched/editor/filemanager/browser/default/frmupload.html 2008-04-08 14:54:53.000000000 +0100 |
---|
4 | @@ -83,6 +83,17 @@ |
---|
5 | case 202 : |
---|
6 | alert( 'Invalid file' ) ; |
---|
7 | break ; |
---|
8 | + case 205 : |
---|
9 | + window.parent.frames['frmResourcesList'].Refresh() ; |
---|
10 | + alert( 'Your file has been successfully uploaded, and replaced the existing file with the same name.' ) ; |
---|
11 | + break ; |
---|
12 | + case 206 : |
---|
13 | + alert( 'A file of that name already exists, so the upload failed.' ) ; |
---|
14 | + break ; |
---|
15 | + case 207 : |
---|
16 | + window.parent.frames['frmResourcesList'].Refresh() ; |
---|
17 | + alert( 'Your file has been successfully uploaded. There was already a file of that name, so that previous file has been backed up by being renamed to "' + data + '".' ) ; |
---|
18 | + break ; |
---|
19 | default : |
---|
20 | alert( 'Error on file upload. Error number: ' + errorNumber ) ; |
---|
21 | break ; |
---|
22 | diff -Nru FCKeditor_2.6-virgin/editor/filemanager/connectors/php/commands.php FCKeditor_2.6-patched/editor/filemanager/connectors/php/commands.php |
---|
23 | --- FCKeditor_2.6-virgin/editor/filemanager/connectors/php/commands.php 2008-02-25 16:43:22.000000000 +0000 |
---|
24 | +++ FCKeditor_2.6-patched/editor/filemanager/connectors/php/commands.php 2008-04-08 14:58:37.000000000 +0100 |
---|
25 | @@ -202,20 +202,61 @@ |
---|
26 | // Check if it is an allowed extension. |
---|
27 | if ( !$sErrorNumber && IsAllowedExt( $sExtension, $resourceType ) ) |
---|
28 | { |
---|
29 | - $iCounter = 0 ; |
---|
30 | - |
---|
31 | - while ( true ) |
---|
32 | - { |
---|
33 | - $sFilePath = $sServerDir . $sFileName ; |
---|
34 | - |
---|
35 | - if ( is_file( $sFilePath ) ) |
---|
36 | - { |
---|
37 | - $iCounter++ ; |
---|
38 | - $sFileName = RemoveExtension( $sOriginalFileName ) . '(' . $iCounter . ').' . $sExtension ; |
---|
39 | - $sErrorNumber = '201' ; |
---|
40 | - } |
---|
41 | - else |
---|
42 | - { |
---|
43 | + /* Server-side half of patch to implement filename clash behaviour control */ |
---|
44 | + // Assign the new file's name |
---|
45 | + $sFilePath = $sServerDir . $sFileName ; |
---|
46 | + $doUpload = true; |
---|
47 | + |
---|
48 | + // If the file already exists, select what behaviour should be adopted |
---|
49 | + if ( is_file( $sFilePath ) ) { |
---|
50 | + $sFilenameClashBehaviour = (isSet ($Config['FilenameClashBehaviour']) ? $Config['FilenameClashBehaviour'] : 'newname'); |
---|
51 | + switch ($sFilenameClashBehaviour) { |
---|
52 | + |
---|
53 | + // overwrites the version on the server with the same name |
---|
54 | + case 'overwrite': |
---|
55 | + $sErrorNumber = '205' ; |
---|
56 | + // Do nothing - move_uploaded_file will just overwrite naturally |
---|
57 | + break; |
---|
58 | + |
---|
59 | + // generate an error so that the file uploading fails |
---|
60 | + case false: |
---|
61 | + case 'false': // String version in case someone quotes the boolean text equivalent |
---|
62 | + $sErrorNumber = '206' ; |
---|
63 | + $doUpload = false; |
---|
64 | + break; |
---|
65 | + |
---|
66 | + // give the uploaded file a new name (this was the (unconfigurable) behaviour in FCKeditor2.5) - named as: originalName(number).extension |
---|
67 | + case 'newname': |
---|
68 | + $iCounter = 0 ; |
---|
69 | + while ( true ) |
---|
70 | + { |
---|
71 | + if ( is_file( $sFilePath ) ) |
---|
72 | + { |
---|
73 | + $iCounter++ ; |
---|
74 | + $sFileName = RemoveExtension( $sOriginalFileName ) . '(' . $iCounter . ').' . $sExtension ; |
---|
75 | + $sErrorNumber = '201' ; |
---|
76 | + $sFilePath = $sServerDir . $sFileName ; |
---|
77 | + } |
---|
78 | + else |
---|
79 | + { |
---|
80 | + break ; |
---|
81 | + } |
---|
82 | + } |
---|
83 | + break; |
---|
84 | + |
---|
85 | + // (default behaviour) back up the version on the server to the same name + timestamp appended to the filename (after the extension) |
---|
86 | + case 'renameold': |
---|
87 | + default: |
---|
88 | + $timestamp = '.' . date ('Ymd-His'); |
---|
89 | + copy ($sFilePath, $sFilePath . $timestamp); |
---|
90 | + $sFileName = $sFileName . $timestamp; |
---|
91 | + $sErrorNumber = '207' ; |
---|
92 | + break; |
---|
93 | + } // End of switch statement |
---|
94 | + } |
---|
95 | + |
---|
96 | + // Now its name has been assigned, move the uploaded file into position |
---|
97 | + if ($doUpload) { |
---|
98 | move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ; |
---|
99 | |
---|
100 | if ( is_file( $sFilePath ) ) |
---|
101 | @@ -236,9 +277,6 @@ |
---|
102 | chmod( $sFilePath, $permissions ) ; |
---|
103 | umask( $oldumask ) ; |
---|
104 | } |
---|
105 | - |
---|
106 | - break ; |
---|
107 | - } |
---|
108 | } |
---|
109 | |
---|
110 | if ( file_exists( $sFilePath ) ) |
---|
111 | diff -Nru FCKeditor_2.6-virgin/editor/filemanager/connectors/php/config.php FCKeditor_2.6-patched/editor/filemanager/connectors/php/config.php |
---|
112 | --- FCKeditor_2.6-virgin/editor/filemanager/connectors/php/config.php 2008-03-25 15:28:24.000000000 +0000 |
---|
113 | +++ FCKeditor_2.6-patched/editor/filemanager/connectors/php/config.php 2008-04-08 14:56:44.000000000 +0100 |
---|
114 | @@ -57,6 +57,13 @@ |
---|
115 | // following extensions only. |
---|
116 | $Config['HtmlExtensions'] = array("html", "htm", "xml", "xsd", "txt", "js") ; |
---|
117 | |
---|
118 | +// What to do if a file being uploaded has the same name as an existing file on the server |
---|
119 | +// 'renameold' - (default behaviour) backs up the version on the server to the same name + timestamp appended to the filename (after the extension) |
---|
120 | +// 'overwrite' - overwrites the version on the server with the same name |
---|
121 | +// 'newname' - gives the uploaded file a new name (this was the (unconfigurable) behaviour in FCKeditor2.6) |
---|
122 | +// false - generates an error so that the file uploading fails |
---|
123 | +$Config['FilenameClashBehaviour'] = 'renameold'; |
---|
124 | + |
---|
125 | // After file is uploaded, sometimes it is required to change its permissions |
---|
126 | // so that it was possible to access it at the later time. |
---|
127 | // If possible, it is recommended to set more restrictive permissions, like 0755. |
---|
128 | diff -Nru FCKeditor_2.6-virgin/editor/filemanager/connectors/test.html FCKeditor_2.6-patched/editor/filemanager/connectors/test.html |
---|
129 | --- FCKeditor_2.6-virgin/editor/filemanager/connectors/test.html 2008-03-26 08:35:08.000000000 +0000 |
---|
130 | +++ FCKeditor_2.6-patched/editor/filemanager/connectors/test.html 2008-04-08 14:55:26.000000000 +0100 |
---|
131 | @@ -117,6 +117,17 @@ |
---|
132 | case 202 : |
---|
133 | alert( 'Invalid file' ) ; |
---|
134 | break ; |
---|
135 | + case 205 : |
---|
136 | + GetFoldersAndFiles() ; |
---|
137 | + alert( 'Your file has been successfully uploaded, and replaced the existing file with the same name.' ) ; |
---|
138 | + break ; |
---|
139 | + case 206 : |
---|
140 | + alert( 'A file of that name already exists, so the upload failed.' ) ; |
---|
141 | + break ; |
---|
142 | + case 207 : |
---|
143 | + GetFoldersAndFiles() ; |
---|
144 | + alert( 'Your file has been successfully uploaded. There was already a file of that name, so that previous file has been backed up by being renamed to "' + data + '".' ) ; |
---|
145 | + break ; |
---|
146 | default : |
---|
147 | alert( 'Error on file upload. Error number: ' + errorNumber ) ; |
---|
148 | break ; |
---|
149 | diff -Nru FCKeditor_2.6-virgin/editor/filemanager/connectors/uploadtest.html FCKeditor_2.6-patched/editor/filemanager/connectors/uploadtest.html |
---|
150 | --- FCKeditor_2.6-virgin/editor/filemanager/connectors/uploadtest.html 2008-03-26 08:35:08.000000000 +0000 |
---|
151 | +++ FCKeditor_2.6-patched/editor/filemanager/connectors/uploadtest.html 2008-04-08 14:56:02.000000000 +0100 |
---|
152 | @@ -111,6 +111,15 @@ |
---|
153 | case 203 : |
---|
154 | alert( "Security error. You probably don't have enough permissions to upload. Please check your server." ) ; |
---|
155 | break ; |
---|
156 | + case 205 : |
---|
157 | + alert( 'Your file has been successfully uploaded, and replaced the existing file with the same name.' ) ; |
---|
158 | + break ; |
---|
159 | + case 206 : |
---|
160 | + alert( 'A file of that name already exists, so the upload failed.' ) ; |
---|
161 | + break ; |
---|
162 | + case 207 : |
---|
163 | + alert( 'Your file has been successfully uploaded. There was already a file of that name, so that previous file has been backed up by being renamed to "' + data + '".' ) ; |
---|
164 | + break ; |
---|
165 | default : |
---|
166 | alert( 'Error on file upload. Error number: ' + errorNumber ) ; |
---|
167 | break ; |
---|