How to save and rename files uploaded by fckeditor by date _ php instance

Source: Internet
Author: User
This article mainly introduces how to store and rename files uploaded by fckeditor by date. This article modifies the related PHP files to meet these two requirements. For more information, see 1. Implement fckeditor to store uploaded files in the form of a date-based directoryFor example, if today is July 22, all files uploaded today are stored in this directory. files uploaded tomorrow are automatically created and stored in directories similar to May 5, 2015.

(1) Find the config. php file in the editor \ filemanager \ connectors \ php \ folder.

(2) Find the following configuration variables:

View code printing

The Code is as follows:


$ Config ['userfilespath'] = '/uploadfiles /';


Modify the value:

View code printing

The Code is as follows:


$ Config ['userfilespath'] = '/uploadfiles/'. date ('Y-m-d ').'/';


In this way, the uploaded files are stored by date.

2. How to rename the File Uploaded By fckeditor

(1) Find the editor \ filemanager \ connectors \ php \ io. 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;
}
......

To:

The Code is as follows:


Function SanitizeFileName ($ sNewFileName ){
Global $ Config;
$ SNewFileName = stripslashes ($ sNewFileName );
If ($ Config ['forcesingleextension'])
$ SNewFileName = preg_replace ('/\\.(?! [^.] * $)/',' _ ', $ SNewFileName );
// Obtain the extension
$ SExtension = substr ($ sNewFileName, (strrpos ($ sNewFileName, '.') + 1 ));
$ SExtension = strtolower ($ sExtension );
$ SNewFileName = date ("YmdHis"). '.'. $ sExtension;
Return $ sNewFileName;
}

Now the uploaded file will be automatically renamed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.