Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中重命名文件_Php - Fatal编程技术网

在PHP中重命名文件

在PHP中重命名文件,php,Php,如何通过在文件名后面附加.jpg来重命名文件。如屏幕截图所示,这些文件没有扩展名。但是我想在每一个中添加.jpg——是否有php函数用于进行这种批量重命名 只需根据以下内容使用重命名: 如果文件位于目录中: $dir = opendir('directory containing files'); // loop through all the files in the directory while (false !== ($file = readdir($dir))) {

如何通过在文件名后面附加.jpg来重命名文件。如屏幕截图所示,这些文件没有扩展名。但是我想在每一个中添加.jpg——是否有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);

只需根据以下内容使用重命名:

如果文件位于目录中:

$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);
不过,只运行一次,因为如果再运行一次,就会得到
1734.jpg.jpg
之类的结果


不过,只运行一次,因为如果再次运行它,将得到
1734.jpg.jpg
之类的结果。

使用函数
rename()
。文档可在此处找到:


注意:下次用谷歌搜索你的问题;)

使用函数
rename()
。文档可在此处找到:


注意:下次用谷歌搜索你的问题;)

为什么要使用PHP?有,它叫。谁知道呢?可能重复的可能重复的可能重复的为什么要使用PHP?有,它叫做。谁知道呢?可能是重复的,可能是重复的,谢谢你,这就像魔术一样。这为我节省了数小时的手动重命名时间。我很感激,谢谢你,它就像魔术一样。这为我节省了数小时的手动重命名时间。我很感激。