Hongmu Notes
Home Language Notes How to rename a file using PHP?
Language Notes PHP

How to rename a file using PHP?

How to rename a file using PHP?

In PHP, you can use rename() Use a function to rename a file.

Here is an example of uploading a file. oldfile.txt Rename newfile.txt

<?php
$old_filename = 'oldfile.txt';
$new_filename = 'newfile.txt';

if (rename($old_filename, $new_filename)) {
    echo "文件重命名成功.";
} else {
    echo "文件重命名失败.";
}
?>

In the above code,rename() The function accepts two parameters: the original file name and the new file name. If the renaming is successful, the function returns. trueOtherwise, return. false

Please note that,rename() This function can only be used to rename files; it cannot move files to another directory. If you need to move a file to another directory, you can use move_uploaded_file() Function or copy() function.

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

PHP ob function record

PHP ob function record Language Notes PHP

Usage of the following three functions ob_get_contents(); ob_end_clean(); ob_start(); You can use these functions to buffer local files and execute local script code. Use ob_start() to save the output code into the buffer, and the page will not be displayed; then use ob_get_contents to get the data in the buffer. o…
👁 141
PHP preg

PHP preg Language Notes PHP

The preg_match_all function is used to perform a global regular expression match. preg_match_all() Syntax int preg_match_all ( string $pattern , string $subject [, array &$matches [, int $flags = PREG…
👁 169
Detailed explanation of PHP ternary operator and if

Detailed explanation of PHP ternary operator and if Language Notes PHP

Ternary operator condition ? Result 1 : Result 2 Explanation: The position in front of the question mark is the condition for judgment. If the condition is met, the result is 1, and if it is not met, the result is 2. This article compares and explains the ternary operator and if...else... in detail. I hope it will be helpful to everyone. Today when I was revising my paper online, I encountered a statement that I couldn’t understand: $if_summary = $row['IF_SUMMARY']=…
👁 190
PHP cast type

PHP cast type Language Notes PHP PHP collection PHP and mysql

Get the data type 1. If you want to check the value and type of an expression, use var_dump(). 2. If you just want to get an easy-to-read type expression for debugging, use gettype(). 3. To check a certain type, do not use gettype(), but use the is_type() function. Converting Strings to Numbers When a string is evaluated as a number, the result is determined according to the following rules...
👁 232

Recommended reading

(Adaptive mobile version) Responsive Survey and Design Institute blue website PBootCMS template; Download source code for unit/industry association websites – 0551

(Adaptive mobile version) Responsive Survey and Design Institute blue website PBootCMS template; Download source code for unit/industry association websites – 0551 Practical Collection pbootcms Template

A responsive PbootCMS blue website template designed for survey and design institutes, as well as government agencies and industry chambers of commerce/associations; supports both PC and WAP devices. The design features a professional and sophisticated aesthetic, making it ideal for institutions such as design institutes and industry associations to showcase their functions and achievements. This template helps public institutions establish an authoritative online information dissemination platform. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s...
👁 56
Responsive Real Estate Sales and Development Website Template 0169

Responsive Real Estate Sales and Development Website Template 0169 Practical Collection Yiyou template

This EyouCMS responsive template is ideal for real estate sales and development enterprises. Its sophisticated and professional design style effectively showcases property developments, sales information, development case studies, and corporate strength. It helps real estate companies attract homebuyers online and enhance their brand image. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS...
👁 57
Responsive branded sportswear website template – 0984

Responsive branded sportswear website template – 0984 Practical Collection Yiyou template

An eyouCMS responsive website template designed specifically for the branded sportswear industry. Its vibrant and fashionable design is ideal for showcasing sportswear products, brand identity, athletic equipment, and new product launches. This template helps sportswear brands showcase their products online and attract sports enthusiasts. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for YouyouCMS...
👁 51
(PC + WAP) Smart Home Furniture & Building Materials pbootCMS Website Template – Download Custom Red Home Decoration Design Website Source Code: 0552

(PC + WAP) Smart Home Furniture & Building Materials pbootCMS Website Template – Download Custom Red Home Decoration Design Website Source Code: 0552 Practical Collection pbootcms Template

A PbootCMS red template designed for the smart home and furniture/building materials industry, supporting both PC and mobile access. Its sophisticated and festive design makes it ideal for home decoration design firms and custom furniture brands. The template includes built-in modules for case studies, a product center, and online booking – making it a powerful tool for home furnishings and building materials enterprises to enhance their brand image and acquire new customers. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: adm...
👁 55
Responsive real estate project development website template 0170

Responsive real estate project development website template 0170 Practical Collection Yiyou template

An eyouCMS responsive website template designed for real estate development enterprises. Its modern architectural design effectively showcases property projects, development case studies, planning and design work, as well as the company's capabilities. This template helps real estate developers showcase their brand online and attract potential partners. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for eyouCMS...
👁 38