Home  >  Article  >  CMS Tutorial  >  Summarize the method of naming attachments uploaded by Empire CMS to be named with the original file name

Summarize the method of naming attachments uploaded by Empire CMS to be named with the original file name

silencement
silencementforward
2019-11-29 14:22:102739browse

Summarize the method of naming attachments uploaded by Empire CMS to be named 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 of naming is very uncomfortable for users, and it is not conducive to us adjusting or replacing attachments through FTP. Therefore, sometimes we need to change the uploaded attachment to the rule named after the original file name. The specific method is as follows:

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

Search Go to:

The code is as follows:

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

Add below:

The code is as follows:

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

It is recommended to study "Empire cms tutorial

2. Find the code for

as follows:

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

and modify it as:

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 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 Summarize the method of naming attachments uploaded by Empire CMS to be named with the original file name. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:www.word666.com. If there is any infringement, please contact admin@php.cn delete