Note that there are some explanatory texts on larger screens.

plurals
  1. POGallery Is Missing Files From Directory- How To Retrieve All Files From Directory
    primarykey
    data
    text
    <p>I finally got my code to populate a gallery from a directory while using fancybox. It's a basic thumbnail gallery that shows the larger image upon clicking. The only problem is that it is missing a lot of files from the thumbnail directory. </p> <p>The code retrieves all of the links for the larger images but it won't retrieve ALL of the thumbnails, only a few of them and they're not even in order.</p> <p>What is wrong in my code?</p> <pre><code>&lt;?php $directory = 'thumb'; //where the gallery thumbnail images are located $allowed_types=array('jpg','jpeg','gif','png');//allowed image types $file_parts=array(); $ext=''; $title=''; $i=0;//try to open the directory $dir_handle = @opendir($directory) or die("There is an error with your image directory!"); while ($file = readdir($dir_handle)) //traverse through the files { if($file=='.' || $file == '..') continue; //skip links to the current and parent directories $file_parts = explode('.',$file); //split the file name and put each part in an array $ext = strtolower(array_pop($file_parts)); //the last element is the extension $title = implode('.',$file_parts); //once the extension has been popped out, all that is left is the filename $title = htmlspecialchars($title); //make the filename html-safe to prevent potential security issues natsort($file_parts); //sort by filename--NOT WORKING $nomargin=''; if(in_array($ext,$allowed_types)) //check if the extension is an allowable type { if(($i+1)%4==0) $nomargin='nomargin'; //the last image on the row is assigned the CSS class "nomargin" //Begin thumbs containers with fancybox class echo '&lt;div class="thumbs fancybox '.$nomargin.'" style="background:url('.$directory.'/'.$file.') no-repeat 50% 50%;"&gt; &lt;a rel="group" href="images/'.$file.'" title="'.$title.'"&gt;'.$title.'&lt;/a&gt; &lt;/div&gt;'; $i=0; //increment the image counter } } closedir($dir_handle); //close the directory ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload