Advertisement
Filipegr

Untitled

May 30th, 2012
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.19 KB | None | 0 0
  1. /* Scandir */
  2.  
  3. $thumbsDesignPath = "trabalhos/design/thumbs";
  4. $imagesDesignPath = "trabalhos/design/large";
  5. $file_display = array('jpg', 'jpeg', 'png', 'gif');
  6.  
  7. if (file_exists($thumbsDesignPath) == false){
  8.     echo 'Directory \'', $thumbsDesignPath, '\' not found.';
  9. } else {
  10.     if (file_exists($imagesDesignPath) == false){
  11.     echo 'Directory \'', $imagesDesignPath, '\' not found.';
  12.     } else {
  13.         $thumbs_content = scandir($thumbsDesignPath);
  14.         $images_content = scandir($imagesDesignPath);
  15.         $design_content = $thumbs_content + $images_content;
  16.         echo '<pre>'; print_r($design_content); echo '</pre>';
  17.         $counter = 0;
  18.             $filesPerPage = 6;
  19.                 foreach ($design_content as $design_file)
  20.                 {
  21.                 $design_file_type = (end(explode('.', $design_file)));
  22.                     if($design_file !== '.' && $design_file !== '..' && in_array($design_file_type, $file_display) == true){
  23.                                 if($counter == 0){
  24.                                     echo "<li>";
  25.                                     $counter++;
  26.                                     /*$info = pathinfo($file);
  27.                                     $sFile =  basename($file,'.'.$info['extension']);
  28.                                    
  29.                                     $aFiles = glob($images.$sFile."[0-9]+.[".implode($file_display,"|")."]"); //This array shows all images relative to the thumbnail that you are seeing*/
  30.                                     echo '<div class="portfolio_pic_hold"> <a href="'.$imagesDesignPath. '/' .$design_file.'" rel="lightbox[Design]"> <img src="'.$thumbsDesignPath. '/'.$design_file. '" /> </a> </div>';
  31.                                    
  32.                                     if($counter == $filesPerPage){
  33.                                     echo "</li>";
  34.                                     }
  35.                                 }
  36.                         }
  37.                 }
  38.         }
  39.  
  40.     }
  41.  
  42. Result:
  43.  
  44. Array
  45. (
  46.     [0] => .
  47.     [1] => ..
  48.     [2] => pinheirinhonovo.jpg
  49.     [3] => qclass.jpg
  50.     [4] => sylviartz.jpg
  51.     [5] => teresabrito.jpg
  52.     [6] => tgi.jpg
  53.     [7] => valoresremodelados.jpg
  54.     [8] => videoclubebaviera.jpg
  55.     [9] => xtremenutrition.jpg
  56. )
  57.  
  58. /* Glob */
  59. $thumbsDesignPath = "trabalhos/design/thumbs/";
  60. $imagesDesignPath = "trabalhos/design/large/";
  61. $file_display = array('jpg', 'jpeg', 'png', 'gif');
  62.  
  63.  
  64. if (file_exists($thumbsDesignPath) == false)
  65. {
  66.     echo 'Directory \'', $thumbsDesignPath, '\' not found.';
  67. }
  68. else
  69. {
  70.         $thumbs = glob($thumbsDesignPath."*.[".implode($file_display,"|")."]");
  71.         print_r($thumbs);
  72.         if (file_exists($imagesDesignPath) == false){
  73.                 echo 'Directory \'', $imagesDesignPath, '\' not found.';
  74.         } else
  75.         {
  76.                 $counter = 0;
  77.                 $filesPerPage = 6;
  78.                 foreach ($thumbs as $file)
  79.                 {
  80.                        
  81.                         if($counter == 0) echo "<li>";
  82.                         $counter++;
  83.                         $info = pathinfo($file);
  84.                         $sFile =  basename($file,'.'.$info['extension']);
  85.                        
  86.                         $aFiles = glob($images.$sFile."[0-9]+.[".implode($file_display,"|")."]"); //Este array tem todas as imagens relativas ao thumbnail que estás a ver
  87.                         echo '<div class="portfolio_pic_hold"><a href="'. $imagesDesignPath. '/'. $file.'"> <img src="'. $thumbsDesignPath . '/' . $file . '" /> </a></div>';
  88.                         if($counter == $filesPerPage) echo "</li>";
  89.                 }
  90.         }
  91. }
  92.  
  93. Result:
  94.  
  95. Array
  96. (
  97. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement