TAV1702 Posted December 15, 2016 Report Share Posted December 15, 2016 (edited) Ok gurus, I need your help once again. This time I am up to no good. Well, it is good so yeah. Anyhow, What I want to do is use some code to pull every image in a directory and display it on a page. I am attempting to do this using the glob function. Problem is, it is wanting to put index.php before my image directory and that breaks the images obviously. if I use the old ../ trick, the page goes blank. If I try to hard code the entire url (which i know is not right and not to do but for testing), same thing, page goes all blank. I have even tried to , even though I knew better, to use use the old php echo url thing and no such love, once again, blank page. Can you please take a peak at my code and let me know if anything stands out at you? <?php $files = glob("./lib/signatures/background/*.*"); for ($i=0; $i<count($files); $i++) { $image = $files[$i]; print $image ."<br />"; echo '<img src="'.$image .'" alt="Profile Badge" />'."<br /><br />"; } notice i added a single ./ ? That does NOT make the page go blank but instead it displays this: ./lib/signatures/background/background.png ./lib/signatures/background/background2.png Now If I am trying to reinvent the wheel, please feel free to call me out on it. I can take it. If there is an easier way to pull off what I want to do, by all means please do crack me up side the head and say listen up Ray. Maybe this little lesson will enrich us all in a new style of doing things or even a page to use on our va website. I think the one thing phpVMS has always lacked was the preview badge feature. It has aggravated me more than once. Esentially what this is supposed to do is, if a VA has a vast number of sig badges, say 20 for argument sake, well all we can do as pilots is pick a image name and save and hope we picked a good badge. With this code, there would be a link right next to where one chooses the badge while editing profile that would take them to a created page of my choice , badge_options or what ever and on this page, it would pull every image and display it in list fashion, non clickable. And once a pilot see the badge that he or she so chooses to use, they click the back to profile link and bingo bango, they choose their badge and all is well in the neighborhood. If I right click on where it says Profile Badge, it give me the entire url to my site including index.php in front of the directory. http://XXXXXXXX/XXXXXXXX/index.php/lib/signatures/background/background2.png Thanks for taking a look at my post. I appreciate it. Edited December 15, 2016 by TAV1702 Typos Quote Link to comment Share on other sites More sharing options...
web541 Posted December 15, 2016 Report Share Posted December 15, 2016 (edited) I just whipped this up quickly so it might or might not work (bit hacky) Make a php file called imgcount.php <?php $directory = 'lib/signatures/background/'; $ext = '.png'; $files = glob($directory.'*'.$ext); if($files !== false) { $filecount = count($files); } else { $filecount = 0; } $num = 1; while($num <= $filecount && $num > 0) { echo '<img src="'.$directory.$num.$ext.'" alt="'.$num.'" />'; $num++; } ?> Being a bit 'hacky' so to speak, you need to have a few things in place for it to work Permissions set correctly on the images and the folder itself to allow the script to read it The filename of the images must be set to a number in order (as in 1.png, 2.png, etc.) The script must be placed in the root directory of the installation The script can be accessed by going to http://url.com/imgcount.php Of course, you can modify this all you like as there are many ways to re-code this, and even make it into a module (and utilize some of the API functions if you can find some) and change directories and file extensions, etc. but this was just a quick sketch. Edited December 16, 2016 by web541 Quote Link to comment Share on other sites More sharing options...
TAV1702 Posted December 15, 2016 Author Report Share Posted December 15, 2016 (edited) Thanks Web, I'll take a stab at this and let you know how ti goes man. I really appreciate the reply. **EDIT** Hey Web, that worked. thanks a million man. I really do appreciate your effort on that. One thing I did need to do was echo a couple line breaks as the images were horizontal and not vertical. Now All I have to do is get it in to a module so I can skin the page to match the rest of my site. Thanks gain. It is genuinely appreciated. I hope others can get some use out of this code snippet as well or maybe a badge preview feature could be worked in to the next release of phpVMS out of this code snippet. Got to run for now. Take care man. Ray Edited December 15, 2016 by TAV1702 No Bump Edit Quote Link to comment Share on other sites More sharing options...
web541 Posted December 16, 2016 Report Share Posted December 16, 2016 I edited this into a module if you are interested. https://github.com/web541/phpvms-BadgeView Should do pretty much the same thing, but includes the phpVMS core layout so you can skin it up and add/remove stuff more easily. Quote Link to comment Share on other sites More sharing options...
TAV1702 Posted December 16, 2016 Author Report Share Posted December 16, 2016 Yeah I'll go take a look. I hacked it in to a module earlier today but that is exactly what it is is a hack and I'm not proud of it but it works. lol. I'm going to run over and take a look at your module. it has to be better than what I got going on. Quote Link to comment 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.