david212 Posted February 26, 2009 Share Posted February 26, 2009 Please, can anyone tell me how i can create function that will display only gif files from a folder where are a lot of pictures with other extension too? Thanx Link to comment https://forums.phpfreaks.com/topic/146980-solved-need-help/ Share on other sites More sharing options...
phpdragon Posted February 26, 2009 Share Posted February 26, 2009 $dir = new DirectoryIterator( '/www/test/' ); foreach($dir as $file ) { if(!$file->isDot() && !$file->isDir() && preg_match("/.gif$/",$file->getFilename())) { echo "FileName: ".$file->getFilename(); echo "Size: ".number_format(($file->getSize()/1024),2)." Kb"; } } Link to comment https://forums.phpfreaks.com/topic/146980-solved-need-help/#findComment-771652 Share on other sites More sharing options...
david212 Posted February 26, 2009 Author Share Posted February 26, 2009 Thanks a lot but i have one question: i wrote this code: <?php $myAr = array("1.jpg","2.jpg","3.jpg","4.jpg","5.GIF","6.gif"); $s=sizeof($myAr); for($i=0;$i<$s;$i++){ if($myAr[$i]=="*.jpg"){ echo("<img src = \"pics/".$myAr[$i]."\" width=\"200\" height = \"200\">"); } } ?> where i made mistake? how can i define file extension in this case using "*.jpg", all that i need to know, how can define file extension usind for loop? Thanx Link to comment https://forums.phpfreaks.com/topic/146980-solved-need-help/#findComment-771792 Share on other sites More sharing options...
premiso Posted February 26, 2009 Share Posted February 26, 2009 if(stristr($myAr[$i], ".jpg") !== false){ stristr should fix that for you. Link to comment https://forums.phpfreaks.com/topic/146980-solved-need-help/#findComment-771804 Share on other sites More sharing options...
david212 Posted February 26, 2009 Author Share Posted February 26, 2009 Thank you Link to comment https://forums.phpfreaks.com/topic/146980-solved-need-help/#findComment-771810 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.