AV1611 Posted June 29, 2006 Share Posted June 29, 2006 I have no code snippet because I've never done this and have no idea how or what to read...simple:in the current directory, there are three jpg files, xxx.jpg yyy.jpg zzz.jpg.there may be more or less, I can do pagination no problem there.I simply need it to:a. scan the current directory for .jpg imagesb. create hyperlinks to themeasy, but I don't know how to scan the directory so I can create the links...thanks Quote Link to comment https://forums.phpfreaks.com/topic/13192-display-a-picture/ Share on other sites More sharing options...
heckenschutze Posted June 29, 2006 Share Posted June 29, 2006 It's done with opendir/readdir/closedir, eg:[code]<?php$strDir = "/my/images";if($dHandle = opendir($strDir)){while (false !== ($strFile = readdir($dHandle))){ if($strFile != "." && $strFile != ".." && !is_dir($strFile)) { $arrayExt = explode(".", $strFile); $strExt = $arrayExt[count($arrayExt)-1]; if($strExt == "jpg" || $strExt == "jpeg") echo $strDir . "/" . $strFile; }} closedir($dHandle);}?> [/code]HTH, Zac. Quote Link to comment https://forums.phpfreaks.com/topic/13192-display-a-picture/#findComment-50770 Share on other sites More sharing options...
AV1611 Posted June 29, 2006 Author Share Posted June 29, 2006 So do I simply modify this one line if I want to include bmp png gif also?if($strExt == "jpg" || $strExt == "jpeg" || $strExt == "Whatever")[!--quoteo(post=389201:date=Jun 29 2006, 07:11 AM:name=heckenschutze)--][div class=\'quotetop\']QUOTE(heckenschutze @ Jun 29 2006, 07:11 AM) [snapback]389201[/snapback][/div][div class=\'quotemain\'][!--quotec--]It's done with opendir/readdir/closedir, eg:[code]<?php$strDir = "/my/images";if($dHandle = opendir($strDir)){while (false !== ($strFile = readdir($dHandle))){ if($strFile != "." && $strFile != ".." && !is_dir($strFile)) { $arrayExt = explode(".", $strFile); $strExt = $arrayExt[count($arrayExt)-1]; if($strExt == "jpg" || $strExt == "jpeg") echo $strDir . "/" . $strFile; }} closedir($dHandle);}?> [/code]HTH, Zac.[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/13192-display-a-picture/#findComment-50779 Share on other sites More sharing options...
heckenschutze Posted June 29, 2006 Share Posted June 29, 2006 Yes. Note: I haven't tested it, as I wrote it on the spot. Quote Link to comment https://forums.phpfreaks.com/topic/13192-display-a-picture/#findComment-50783 Share on other sites More sharing options...
AV1611 Posted June 29, 2006 Author Share Posted June 29, 2006 Script works great, but one more question:What about caps? If the file is xxxx.jpGis there a way to fix those, or do I add those permutations to $strExt clause?// EDIT Never mind, I did it like this:<?php$strDir = "./corp/";if($dHandle = opendir($strDir)){while (false !== ($strFile = readdir($dHandle))){ if($strFile != "." && $strFile != ".." && !is_dir($strFile)) { $arrayExt = explode(".", $strFile); $strExt = strtolower($arrayExt[count($arrayExt)-1]); if($strExt == "jpg" || $strExt == "gif" || $strExt == "bmp") //echo $strDir . "/" . $strFile; echo "<a href='". $strDir.$strFile ."'>".$strFile."</a><br/>"; }} closedir($dHandle);}?> Quote Link to comment https://forums.phpfreaks.com/topic/13192-display-a-picture/#findComment-50788 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.