prakash Posted May 16, 2008 Share Posted May 16, 2008 Hi, I have one directory which will contains images having numeric values (say 1.jpg, 2.jpg .......) I wanted to get the filename of that image which is having highest numeric value within the dir. If there is 1.jpg, 2.jpg, 3.jpg, 4.jpg the file having highest numeric value will be 4.jpg is there any easy solution for this or how can I do it Link to comment https://forums.phpfreaks.com/topic/105933-solved-geting-last-files-from-specific-directory/ Share on other sites More sharing options...
947740 Posted May 16, 2008 Share Posted May 16, 2008 scandir($dir,1); This should result in listing them opposite-alphabetically. Link to comment https://forums.phpfreaks.com/topic/105933-solved-geting-last-files-from-specific-directory/#findComment-542859 Share on other sites More sharing options...
prakash Posted May 16, 2008 Author Share Posted May 16, 2008 thaks it's working Link to comment https://forums.phpfreaks.com/topic/105933-solved-geting-last-files-from-specific-directory/#findComment-543057 Share on other sites More sharing options...
947740 Posted May 16, 2008 Share Posted May 16, 2008 No problem. Link to comment https://forums.phpfreaks.com/topic/105933-solved-geting-last-files-from-specific-directory/#findComment-543061 Share on other sites More sharing options...
prakash Posted May 16, 2008 Author Share Posted May 16, 2008 I encounter problems with scandir($dir,1); actually when I have files like 8.jpg, 9.jpg, 10.jpg, 11.jpg it actually display 9.jpg as a highest value or order. so how to resolve this issue. below is my code <?php $scanDir=scandir('images', 1); $intFile=$scanDir[0]; print $intFile; // it prints 9.jpg where it should be 11.jpg ?> Link to comment https://forums.phpfreaks.com/topic/105933-solved-geting-last-files-from-specific-directory/#findComment-543124 Share on other sites More sharing options...
rhodesa Posted May 16, 2008 Share Posted May 16, 2008 You could name your files 0001.jpg, 0002.jpg, etc Link to comment https://forums.phpfreaks.com/topic/105933-solved-geting-last-files-from-specific-directory/#findComment-543129 Share on other sites More sharing options...
prakash Posted May 16, 2008 Author Share Posted May 16, 2008 You could name your files 0001.jpg, 0002.jpg, etc that may be an another option. but for using that I need the increment and decrement value for next and previous image. so how could it be possible 0004+1=0005 or 0004-1=0003 Link to comment https://forums.phpfreaks.com/topic/105933-solved-geting-last-files-from-specific-directory/#findComment-543134 Share on other sites More sharing options...
rhodesa Posted May 16, 2008 Share Posted May 16, 2008 <?php $a = '0004'; $b = $a + 1; // $b is now 5 print str_pad($b,4,STR_PAD_LEFT).".jpg"; ?> Link to comment https://forums.phpfreaks.com/topic/105933-solved-geting-last-files-from-specific-directory/#findComment-543140 Share on other sites More sharing options...
rhodesa Posted May 16, 2008 Share Posted May 16, 2008 another option is to use a database to store the info Link to comment https://forums.phpfreaks.com/topic/105933-solved-geting-last-files-from-specific-directory/#findComment-543142 Share on other sites More sharing options...
prakash Posted May 16, 2008 Author Share Posted May 16, 2008 <?php $a = '0004'; $b = $a + 1; // $b is now 5 print str_pad($b,4,STR_PAD_LEFT).".jpg"; ?> mmm just found the mistake from php.net site str_pad($b, 4, STR_PAD_LEFT).".jpg" should be str_pad($b, 4, "0", STR_PAD_LEFT).".jpg"; correct me if I am wrong and thanks for the help Link to comment https://forums.phpfreaks.com/topic/105933-solved-geting-last-files-from-specific-directory/#findComment-543158 Share on other sites More sharing options...
rhodesa Posted May 16, 2008 Share Posted May 16, 2008 Yeah...I forgot an argument. You got it right. Link to comment https://forums.phpfreaks.com/topic/105933-solved-geting-last-files-from-specific-directory/#findComment-543160 Share on other sites More sharing options...
prakash Posted May 16, 2008 Author Share Posted May 16, 2008 thanks it solved out my problem Link to comment https://forums.phpfreaks.com/topic/105933-solved-geting-last-files-from-specific-directory/#findComment-543161 Share on other sites More sharing options...
947740 Posted May 16, 2008 Share Posted May 16, 2008 Sorry about that. scandir($dir,1) does it inversely alphabetically, and I forgot that it would do that... Link to comment https://forums.phpfreaks.com/topic/105933-solved-geting-last-files-from-specific-directory/#findComment-543233 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.