Home > Article > Backend Development > How to store and rename files uploaded by fckeditor by date_PHP tutorial
This article mainly introduces the method of storing and renaming files uploaded by fckeditor by date. This article modifies the relevant PHP files to achieve this Two requirements, friends in need can refer to the following
1. Implement fckeditor to store uploaded files in directories by date. For example, today is May 5, 2015, then the files uploaded today will be placed in this directory, and the files uploaded tomorrow will be automatically created and placed in Go to a directory like 2015-05-06.
(1) Find the config.php file in the editoreditorfilemanagerconnectorsphp folder
(2) Find the following configuration variables
View code printing
The code is as follows:
$Config['UserFilesPath'] = '/uploadfiles/';
Modify its value to:
View code printing
The code is as follows:
$Config['UserFilesPath'] = '/uploadfiles/'.date('Y-m-d').'/';
The uploaded files will be stored according to date.
2. How to rename files uploaded by fckeditor
(1) Find the editoreditorfilemanagerconnectorsphpio.php file:
(2) Find the following content:
The code is as follows:
……
Function SanitizeFileName( $sNewFileName ){
global $Config ;
$sNewFileName = stripslashes( $sNewFileName ) ;
if ( $Config['ForceSingleExtension'] )
$sNewFileName = preg_replace( '/\.(?![^.]*$)/', '_', $sNewFileName ) ;
$sNewFileName = preg_replace( '/\\|\/|\||\:|\?|\*|"|<|>/', '_', $sNewFileName );
return $sNewFileName ;
}
……
Modified to:
The code is as follows:
Function SanitizeFileName( $sNewFileName ){
global $Config ;
$sNewFileName = stripslashes( $sNewFileName ) ;
if ( $Config['ForceSingleExtension'] )
$sNewFileName = preg_replace( '/\.(?![^.]*$)/', '_', $sNewFileName ) ;
//Get extension
$sExtension = substr( $sNewFileName, ( strrpos($sNewFileName, '.') 1 ) ) ;
$sExtension = strtolower( $sExtension ) ;
$sNewFileName = date("YmdHis").'.'.$sExtension;
return $sNewFileName ;
}
Now the uploaded file will be automatically renamed.