How to rename list of images in php

<?php
$directory = “folder_name/”;       // Folder name of  images

//get all image files with a .jpg extension.
$images = glob($directory . “*.jpg”);

$i= 1;
foreach ($images as $fileinfo) {
$fromImg = “D:/xampp/htdocs/imagesize/”.$fileinfo; // Read  all images of you directroy
$imageName = “gallery”.$i.”.jpg”;  // Rename your own way
$toImg = “D:/xampp/htdocs/imagesize/rename/”.$imageName; //Rename images location
copy($fromImg,$toImg);
$i++;
}
?>

Hope it will work.