Home  >  Article  >  CMS Tutorial  >  How does Imperial CMS name attachments with original file names?

How does Imperial CMS name attachments with original file names?

藏色散人
藏色散人Original
2019-11-18 10:59:522149browse

How does Imperial CMS name attachments with original file names?

How does Empire CMS name the attachment with the original file name?

When Empire CMS uploads the last attachment through the editor's upload attachment function, the original program will rename the attachment, and the naming results will be named with a long string of alphanumeric combinations. This form The naming method is very uncomfortable for users and is not conducive to us adjusting or replacing attachments through FTP.

Therefore, sometimes we need to change the uploaded attachment to the rule of naming it with the original file name. The specific method is as follows:

Recommended: "Empire cms website building tutorial

1. Open the file \e\class\connect.php

Find:

The code is as follows:

$r[filetype]=GetFiletype($file_name);

Add it below :

The code is as follows:

$filename2=str_replace($r[filetype], '', $file_name);//获得去掉后缀的文件名
$mytype = array (".txt", ".rar", ".zip", ".doc", ".docx", ".xlsx", ".ppt", ".pdf");//定义需要保留原名的文件类型

2. Find

The code is as follows:

$r[filename]=$r[insertfile].$r[filetype];

Change to:

The code is as follows:

if(in_array($r[filetype],$mytype)){
$r[filename]=$filename2."_".$r[insertfile].$r[filetype];//将真实文件名加在随机码的前面中间以_分隔
}
else
{
$r[filename]=$r[insertfile].$r[filetype];
}

The modification is now completed!

Additional explanation:

The code is as follows:

$mytype = array (".txt", ".rar", ".zip", ".doc", ".docx", ".xlsx", ".ppt", ".pdf");

This sentence defines which file types need to be added with the source file name.

.$r[insertfile] This represents the random code

.$r[filetype] This represents the file type

$filename2 This represents the original file name

The above is the detailed content of How does Imperial CMS name attachments with original file names?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn