【发布时间】:2019-03-10 16:32:40
【问题描述】:
我想使用 PHP 将所有图像文件从我的图像文件夹复制到新文件夹。我尝试了下面的代码,但出现了错误。
<?php
$old_dir = 'images/';
$new_dir = 'images/new_update';
$scanned_directory = preg_grep('/^([^.])/', scandir($old_dir));
foreach ($scanned_directory as $key ) {
$source_file = $old_dir.$key;
$destination_path = $new_dir;
if(rename($source_file.'/'.$key,$destination_path.'/'.$key))
echo "Success";
else
echo "Fail";
}
?>
错误:警告:重命名(images/Screenshot 2019-02-04 at 1.24.35 PM.png/Screenshot 2019-02-04 at 1.24.35 PM.png,images/del//Screenshot 2019-02-04在 1.24.35 PM.png):不是第 12 行 /Applications/XAMPP/xamppfiles/htdocs/spartanlink/news/gallery/scandir.php 中的目录
我不知道为什么会出现这个错误。感谢您的帮助
【问题讨论】:
-
我认为您可以重命名文件夹,创建一个新文件夹并将一个文件夹放入另一个文件夹中?
标签: php