Jump to content

Listing File, Directory's


Mod-Jay

Recommended Posts

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 } ?>

Link to comment
https://forums.phpfreaks.com/topic/234722-listing-file-directorys/
Share on other sites

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 } ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.