如何通过将.jpg附加到文件名来重命名文件。如截图所示,这些文件没有扩展名。但是我想给每一个都添加.jpg --有没有一个php函数来做这样的批量重命名?
http://www.jroller.com/sennheiserheadphones/resource/imagename.jpg
发布于 2011-10-18 19:30:24
foreach(glob("*") as $f) rename($f,$f.".jpg");
不过,只运行一次,因为如果再运行一次,就会得到1734.jpg.jpg
之类的结果。
发布于 2011-10-18 19:30:19
只需使用rename,per:
http://php.net/manual/en/function.rename.php
如果文件位于某个目录中:
$dir = opendir('directory containing files');
// loop through all the files in the directory
while (false !== ($file = readdir($dir)))
{
rename($file, $file.".jpg");
}
// close the directory handle
closedir($dir);
发布于 2011-10-18 19:30:47
使用函数rename()
。文档可以在这里找到:http://php.net/manual/en/function.rename.php
注:下次在谷歌上搜索你的问题;)
https://stackoverflow.com/questions/7806484
复制相似问题