![](/img/trans.png)
[英]How to copy the set of files from one folder to another folder using php
[英]How to copy multiple files from one folder to another with specific file names using php?
我有兩個文件夾,其中一個文件夾為空,另一個文件夾有5個圖像文件,它們分別名為:image1,image2,image3,image4和image5。 我想使用php將image2,image4和image5同時移動或復制到另一個文件夾。 如何使用php將多個文件從一個文件夾復制到另一個具有特定文件名的文件夾? 請幫助我,謝謝。
重命名功能可以做到這一點
圖片重命名
rename('image2.jpg', 'newfolder/image2.jpg');
rename('image4.jpg', 'newfolder/image4.jpg');
rename('image5.jpg', 'newfolder/image5.jpg');
如果要將現有文件保留在同一位置,則應使用復制
圖片復制
copy('image2.jpg', 'newfolder/image2.jpg');
copy('image4.jpg', 'newfolder/image4.jpg');
copy('image5.jpg', 'newfolder/image5.jpg');
對多個文件使用循環,如下所示:
//Create an array with image files which should be copy or move in new folder
$files = ['image2.jpg','image4.jpg','image5.jpg'];
foreach($files as $resFile){
rename($resFile, 'newfolder/'.$resFile);
copy($resFile, 'newfolder/'.$resFile);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.