search
Homephp教程PHP源码PHP移动文件或者文件夹

看到很多人都是用,copy,unlink来实现文件的移动,对于大文件,可能会消耗很长时间, 
但是有个更加方便的方式,就是使用php的rename.  

有几种情况:

1.对于文件,rename可以在不同盘符之间移动.

2.对于空文件夹,rename也可以在不同盘符之间移动.但是目标文件夹的父目录必须存在.

3.对于非空文件夹,只能在同一盘符下移动.

不过,1和3,应该差不多能够对付所有的应用情况了.

rename("D:/logs/write/theme/history","F:/logs/write/theme/history");

?>

我测试过,对于一个40M的文件,copy+unlink方式需要7.6249899864197秒

而rename方式,只需要0.024738788604736,快300倍.

因此,谨慎使用copy+unlink方式.

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor