diff -Nru FCKeditor_2.6-virgin/editor/filemanager/browser/default/frmupload.html FCKeditor_2.6-patched/editor/filemanager/browser/default/frmupload.html --- FCKeditor_2.6-virgin/editor/filemanager/browser/default/frmupload.html 2008-03-20 13:02:52.000000000 +0000 +++ FCKeditor_2.6-patched/editor/filemanager/browser/default/frmupload.html 2008-04-08 14:54:53.000000000 +0100 @@ -83,6 +83,17 @@ case 202 : alert( 'Invalid file' ) ; break ; + case 205 : + window.parent.frames['frmResourcesList'].Refresh() ; + alert( 'Your file has been successfully uploaded, and replaced the existing file with the same name.' ) ; + break ; + case 206 : + alert( 'A file of that name already exists, so the upload failed.' ) ; + break ; + case 207 : + window.parent.frames['frmResourcesList'].Refresh() ; + 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 + '".' ) ; + break ; default : alert( 'Error on file upload. Error number: ' + errorNumber ) ; break ; diff -Nru FCKeditor_2.6-virgin/editor/filemanager/connectors/php/commands.php FCKeditor_2.6-patched/editor/filemanager/connectors/php/commands.php --- FCKeditor_2.6-virgin/editor/filemanager/connectors/php/commands.php 2008-02-25 16:43:22.000000000 +0000 +++ FCKeditor_2.6-patched/editor/filemanager/connectors/php/commands.php 2008-04-08 14:58:37.000000000 +0100 @@ -202,20 +202,61 @@ // Check if it is an allowed extension. if ( !$sErrorNumber && IsAllowedExt( $sExtension, $resourceType ) ) { - $iCounter = 0 ; - - while ( true ) - { - $sFilePath = $sServerDir . $sFileName ; - - if ( is_file( $sFilePath ) ) - { - $iCounter++ ; - $sFileName = RemoveExtension( $sOriginalFileName ) . '(' . $iCounter . ').' . $sExtension ; - $sErrorNumber = '201' ; - } - else - { + /* Server-side half of patch to implement filename clash behaviour control */ + // Assign the new file's name + $sFilePath = $sServerDir . $sFileName ; + $doUpload = true; + + // If the file already exists, select what behaviour should be adopted + if ( is_file( $sFilePath ) ) { + $sFilenameClashBehaviour = (isSet ($Config['FilenameClashBehaviour']) ? $Config['FilenameClashBehaviour'] : 'newname'); + switch ($sFilenameClashBehaviour) { + + // overwrites the version on the server with the same name + case 'overwrite': + $sErrorNumber = '205' ; + // Do nothing - move_uploaded_file will just overwrite naturally + break; + + // generate an error so that the file uploading fails + case false: + case 'false': // String version in case someone quotes the boolean text equivalent + $sErrorNumber = '206' ; + $doUpload = false; + break; + + // give the uploaded file a new name (this was the (unconfigurable) behaviour in FCKeditor2.5) - named as: originalName(number).extension + case 'newname': + $iCounter = 0 ; + while ( true ) + { + if ( is_file( $sFilePath ) ) + { + $iCounter++ ; + $sFileName = RemoveExtension( $sOriginalFileName ) . '(' . $iCounter . ').' . $sExtension ; + $sErrorNumber = '201' ; + $sFilePath = $sServerDir . $sFileName ; + } + else + { + break ; + } + } + break; + + // (default behaviour) back up the version on the server to the same name + timestamp appended to the filename (after the extension) + case 'renameold': + default: + $timestamp = '.' . date ('Ymd-His'); + copy ($sFilePath, $sFilePath . $timestamp); + $sFileName = $sFileName . $timestamp; + $sErrorNumber = '207' ; + break; + } // End of switch statement + } + + // Now its name has been assigned, move the uploaded file into position + if ($doUpload) { move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ; if ( is_file( $sFilePath ) ) @@ -236,9 +277,6 @@ chmod( $sFilePath, $permissions ) ; umask( $oldumask ) ; } - - break ; - } } if ( file_exists( $sFilePath ) ) diff -Nru FCKeditor_2.6-virgin/editor/filemanager/connectors/php/config.php FCKeditor_2.6-patched/editor/filemanager/connectors/php/config.php --- FCKeditor_2.6-virgin/editor/filemanager/connectors/php/config.php 2008-03-25 15:28:24.000000000 +0000 +++ FCKeditor_2.6-patched/editor/filemanager/connectors/php/config.php 2008-04-08 14:56:44.000000000 +0100 @@ -57,6 +57,13 @@ // following extensions only. $Config['HtmlExtensions'] = array("html", "htm", "xml", "xsd", "txt", "js") ; +// What to do if a file being uploaded has the same name as an existing file on the server +// 'renameold' - (default behaviour) backs up the version on the server to the same name + timestamp appended to the filename (after the extension) +// 'overwrite' - overwrites the version on the server with the same name +// 'newname' - gives the uploaded file a new name (this was the (unconfigurable) behaviour in FCKeditor2.6) +// false - generates an error so that the file uploading fails +$Config['FilenameClashBehaviour'] = 'renameold'; + // After file is uploaded, sometimes it is required to change its permissions // so that it was possible to access it at the later time. // If possible, it is recommended to set more restrictive permissions, like 0755. diff -Nru FCKeditor_2.6-virgin/editor/filemanager/connectors/test.html FCKeditor_2.6-patched/editor/filemanager/connectors/test.html --- FCKeditor_2.6-virgin/editor/filemanager/connectors/test.html 2008-03-26 08:35:08.000000000 +0000 +++ FCKeditor_2.6-patched/editor/filemanager/connectors/test.html 2008-04-08 14:55:26.000000000 +0100 @@ -117,6 +117,17 @@ case 202 : alert( 'Invalid file' ) ; break ; + case 205 : + GetFoldersAndFiles() ; + alert( 'Your file has been successfully uploaded, and replaced the existing file with the same name.' ) ; + break ; + case 206 : + alert( 'A file of that name already exists, so the upload failed.' ) ; + break ; + case 207 : + GetFoldersAndFiles() ; + 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 + '".' ) ; + break ; default : alert( 'Error on file upload. Error number: ' + errorNumber ) ; break ; diff -Nru FCKeditor_2.6-virgin/editor/filemanager/connectors/uploadtest.html FCKeditor_2.6-patched/editor/filemanager/connectors/uploadtest.html --- FCKeditor_2.6-virgin/editor/filemanager/connectors/uploadtest.html 2008-03-26 08:35:08.000000000 +0000 +++ FCKeditor_2.6-patched/editor/filemanager/connectors/uploadtest.html 2008-04-08 14:56:02.000000000 +0100 @@ -111,6 +111,15 @@ case 203 : alert( "Security error. You probably don't have enough permissions to upload. Please check your server." ) ; break ; + case 205 : + alert( 'Your file has been successfully uploaded, and replaced the existing file with the same name.' ) ; + break ; + case 206 : + alert( 'A file of that name already exists, so the upload failed.' ) ; + break ; + case 207 : + 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 + '".' ) ; + break ; default : alert( 'Error on file upload. Error number: ' + errorNumber ) ; break ;