diff -ru FCKeditor_2.5-virgin/editor/filemanager/browser/default/frmupload.html FCKeditor_2.5-patched/editor/filemanager/browser/default/frmupload.html --- FCKeditor_2.5-virgin/editor/filemanager/browser/default/frmupload.html 2007-07-10 13:47:30.000000000 +0100 +++ FCKeditor_2.5-patched/editor/filemanager/browser/default/frmupload.html 2007-12-10 19:28:51.000000000 +0000 @@ -82,6 +82,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 -ru FCKeditor_2.5-virgin/editor/filemanager/connectors/php/commands.php FCKeditor_2.5-patched/editor/filemanager/connectors/php/commands.php --- FCKeditor_2.5-virgin/editor/filemanager/connectors/php/commands.php 2007-10-02 19:15:16.000000000 +0100 +++ FCKeditor_2.5-patched/editor/filemanager/connectors/php/commands.php 2007-12-10 19:37:40.000000000 +0000 @@ -201,30 +201,66 @@ // Check if it is an allowed extension. if ( !$sErrorNumber && IsAllowedExt( $sExtension, $resourceType ) ) { - $iCounter = 0 ; - - while ( true ) - { - $sFilePath = $sServerDir . $sFileName ; - + // 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 ) ) { - $iCounter++ ; - $sFileName = RemoveExtension( $sOriginalFileName ) . '(' . $iCounter . ').' . $sExtension ; - $sErrorNumber = '201' ; - } - else - { - move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ; - - if ( is_file( $sFilePath ) ) - { - $oldumask = umask(0) ; - chmod( $sFilePath, 0777 ) ; - umask( $oldumask ) ; - } - - break ; + $oldumask = umask(0) ; + chmod( $sFilePath, 0777 ) ; + umask( $oldumask ) ; } } } diff -ru FCKeditor_2.5-virgin/editor/filemanager/connectors/php/config.php FCKeditor_2.5-patched/editor/filemanager/connectors/php/config.php --- FCKeditor_2.5-virgin/editor/filemanager/connectors/php/config.php 2007-11-21 17:46:48.000000000 +0000 +++ FCKeditor_2.5-patched/editor/filemanager/connectors/php/config.php 2007-12-10 19:39:53.000000000 +0000 @@ -57,6 +57,14 @@ // 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.2) +// false - generates an error so that the file uploading fails +$Config['FilenameClashBehaviour'] = 'renameold'; + + /* Configuration settings for each Resource Type diff -ru FCKeditor_2.5-virgin/editor/filemanager/connectors/test.html FCKeditor_2.5-patched/editor/filemanager/connectors/test.html --- FCKeditor_2.5-virgin/editor/filemanager/connectors/test.html 2007-07-10 13:47:30.000000000 +0100 +++ FCKeditor_2.5-patched/editor/filemanager/connectors/test.html 2007-12-10 19:29:44.000000000 +0000 @@ -84,6 +84,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 -ru FCKeditor_2.5-virgin/editor/filemanager/connectors/uploadtest.html FCKeditor_2.5-patched/editor/filemanager/connectors/uploadtest.html --- FCKeditor_2.5-virgin/editor/filemanager/connectors/uploadtest.html 2007-08-31 16:08:32.000000000 +0100 +++ FCKeditor_2.5-patched/editor/filemanager/connectors/uploadtest.html 2007-12-10 19:29:29.000000000 +0000 @@ -73,6 +73,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 ;