I am practicing PHP on my computer using PHPStorm. I have a directory full of images that I placed in my project. These images were pulled off of a web page and all have names such as "attachment_56602224.jpg." I want to rename them to all numbers (like 1.jpg, 2.jpg) just for simplicity. Here's what I have so far:
$i = 1;
if ($handle = opendir('pics')) {
while (false !== ($fileName = readdir($handle))) {
rename($fileName, $i);
$i++;
}
closedir($handle);
}
Here is the error I am getting when I run it in my browser:
Warning: rename(.,1): The process cannot access the file because it is being used by another process. (code: 32) in C:\Users\Mike\PhpstormProjects\php\learn.php on line 12
Warning: rename(..,2): Access is denied. (code: 5) in C:\Users\Mike\PhpstormProjects\php\learn.php on line 12
Warning: rename(attachment_56602224.jpg,3): The system cannot find the file specified. (code: 2) in C:\Users\Mike\PhpstormProjects\php\learn.php on line 12
And that last error repeats for every image.