bmw2213 Posted July 1, 2009 Share Posted July 1, 2009 Basically, I have a directory of jpgs named IMG_3454.JPG where the 3454 changes for every picture. There are a lot of files that were deleted so do not exist. I just downloaded the pictures from a camera and uploaded them onto my server. Now I want to rename them into 1.JPG, 2.JPG, etc. so I can easily make a while loop to display the pictures. My current code is: <?php $path = "/maggie/"; $dh = opendir($path); $i=1; while (($file = readdir($dh)) !== false) { if($file != "." && $file != "..") { $newname = $i.".JPG"; rename($path."//".$file, $newname); $i++; } } closedir($dh); ?> But it doesn't seem to be working. Anything I am missing here? Link to comment https://forums.phpfreaks.com/topic/164414-solved-question-about-renaming-all-files-in-a-directory/ Share on other sites More sharing options...
flyhoney Posted July 1, 2009 Share Posted July 1, 2009 <?php // Always turn on error reporting when you are debugging error_reporting(E_ALL); ini_set('display_errors', 1); $path = "/maggie/"; $dh = opendir($path); $i = 1; while (($file = readdir($dh)) !== FALSE) { if ($file != "." and $file != "..") { $oldname = "$path/$file"; $newname = "$path/$i.JPG"; rename($oldname, $newname); $i++; } } Link to comment https://forums.phpfreaks.com/topic/164414-solved-question-about-renaming-all-files-in-a-directory/#findComment-867278 Share on other sites More sharing options...
bmw2213 Posted July 1, 2009 Author Share Posted July 1, 2009 Thanks, that helped, I got it figured it out. Link to comment https://forums.phpfreaks.com/topic/164414-solved-question-about-renaming-all-files-in-a-directory/#findComment-867291 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.