Home > php教程 > PHP源码 > body text

PHP移动文件或者文件夹

PHP中文网
Release: 2016-05-25 17:11:50
Original
1401 people have browsed it

看到很多人都是用,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方式.

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!