如何将特定图像移动到新文件夹php

时间:2016-05-23 23:49:01

标签: php

我有一个包含一些图片pic1.jpg, pic2.jpg, pic3.jpg, frame2.jpg. round.jpg的文件夹。我的问题是如何只将pic*.jpg图像移动到新文件夹而不使用php添加其他图像frame*.jpground.jpg

2 个答案:

答案 0 :(得分:1)

使用php globbasename

foreach(glob("/old/pic*.jpg") as $file)
{
    rename($file, "/new/".basename($file));
}

答案 1 :(得分:0)

// search for all the pathnames matching pattern
foreach(glob("/myfolder/pic*.jpg") as $file)
{ 
// check if newfolder exists, if not create it
if(!is_dir('/newfolder') && !file_exists('/newfolder')) {
mkdir('/newfolder', 0755);
}
// new file path
$newfile = '/newfolder/'.basename($file);
// copy file to new location
copy($file, $newfile);
}