Mod-Jay Posted April 26, 2011 Share Posted April 26, 2011 Hey, I dont know whats wrong but i was hoping someone could take a look at the code and provide some errors that maybe causing this script not to work. I want it to display all the .jpg pictures in thumbnails, it currently does not even get the pictures. code: <?php $pic_listing = mysql_query("SELECT * FROM toplist WHERE id='". $id ."'") or die(mysql_error()); while($serverpic = mysql_fetch_array($pic_listing)) { $servername = $serverpic["servername"]; } $directory = "images/serverpic/" . $servername . ""; $images = glob("" . $directory . "*.jpg"); if(empty($images)) { ?> <div class="highslide-gallery"> <?php foreach($images as $image) { ?> <a href="images/serverpic/<?php echo $servername . "/" . $image; ?>" class="highslide" onclick="return hs.expand(this)"> <img src="images/serverpic/<?php echo $servername . "/" . $image; ?>" alt="Highslide JS" width="100" height="100" title="Click to enlarge" /> </a> <div class="highslide-caption"> <?php } ?> </div> </div> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/234722-listing-file-directorys/ Share on other sites More sharing options...
fugix Posted April 26, 2011 Share Posted April 26, 2011 so what exactly do you have stored in your db? if I have a picture name "test.jpg"...would servername=test? Quote Link to comment https://forums.phpfreaks.com/topic/234722-listing-file-directorys/#findComment-1206229 Share on other sites More sharing options...
fugix Posted April 26, 2011 Share Posted April 26, 2011 also, my preference is to use opendir() rather than glob().. Quote Link to comment https://forums.phpfreaks.com/topic/234722-listing-file-directorys/#findComment-1206231 Share on other sites More sharing options...
Fadion Posted April 26, 2011 Share Posted April 26, 2011 I rewrote the script for you, fixing a few things and suggesting some others. Try it now and see if it works. <?php $results = mysql_query("SELECT * FROM toplist WHERE id='". $id ."'") or die(mysql_error()); /* ** No need to loop records with while() if you know there will be ** only one row returned. */ $values = mysql_fetch_array($results); $server_name = $values['servername']; /* ** Guess you need to put a trailing slash after $servername (I already did). ** Would not be the case if $servername returns "directory/". */ $dir = "images/serverpic/$server_name/"; $images = glob($dir . '*.jpg'); /* ** Guess you meant here NOT empty. Otherwise, the gallery will show only ** if the $images array is empty. Fixed that for you. */ if (!empty($images)) { ?> <div class="highslide-gallery"> <?php foreach ($images as $img) { ?> <a href="<?php echo $dir . $img; ?>" class="highslide" onclick="return hs.expand(this)"> <!-- Forcing an image to specified dimensions with HTML will result not only in ugly thumbnails, but in full-sized images to be loaded as those ugly thumbnails. Generate thumbnails with a batch resizer, or make a PHP script that utilizes GD to resize/crop them. --> <img src="<?php echo $dir . $img; ?>" alt="Highslide JS" width="100" height="100" title="Click to enlarge" /> </a> <div class="highslide-caption"></div> <?php } ?> </div> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/234722-listing-file-directorys/#findComment-1206240 Share on other sites More sharing options...
Mod-Jay Posted April 26, 2011 Author Share Posted April 26, 2011 The thumbnails show but the pictures do not. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/234722-listing-file-directorys/#findComment-1206242 Share on other sites More sharing options...
Fadion Posted April 26, 2011 Share Posted April 26, 2011 How can't the images show on click and show on thumbnails? They have the same exact url! You sure HighSlide works? Try placing a known image link in the href part to see if highslide is working. Quote Link to comment https://forums.phpfreaks.com/topic/234722-listing-file-directorys/#findComment-1206248 Share on other sites More sharing options...
Mod-Jay Posted April 26, 2011 Author Share Posted April 26, 2011 Highslide does indeed work. EDIT: found your problem, you had <?php echo $dir . $img; ?>, it needed to be <?php echo $img; ?> cause you already echo'd "$dir" in images. Quote Link to comment https://forums.phpfreaks.com/topic/234722-listing-file-directorys/#findComment-1206254 Share on other sites More sharing options...
fugix Posted April 26, 2011 Share Posted April 26, 2011 Glad you got it figured out Quote Link to comment https://forums.phpfreaks.com/topic/234722-listing-file-directorys/#findComment-1206256 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.