Topic: snippet portfolio

Looking for images and insert them into the web.

<!--[if gte IE 8]>
<style type="text/css">
    .port-img-ie{
        width:100%; /* example for ie */
        height:180px; /* example for ie */
    }
</style>
<![endif]-->
<table class="">
     <tr>
    <?php
        $path = 'public/uploads'; # Directory Images
        $limit = 16; # How many images are displayed per page
        $limit_file = 4; # Pictures to show per line in the table
        $n = 0;
        $from;
        $to;
         // Check if a directory
        if (is_dir($path)){
            $dir = opendir($path);
        while (false !== ($file = readdir($dir))) {
        if (preg_match("#([a-zA-Z0-9_\-\s]+)\.(gif|GIF|jpg|JPG|png|PNG)#is",$file)){
            $list[] = $file;
        }}
        // close directory
        closedir($dir);
        // We order the list
         sort ($list);
         // Count the total items in list
        $total = count($list);
        $pages = ceil($total/$limit);
        if (!isset($_GET['pg'])){
            $from = 0;
            $to = $from + $limit;
        }else if((int)$_GET['pg'] > ($pages-1)){
        // If pg is greater than the total page displays an error
             echo "<b>No such product in the gallery</b>";
            die();
        }else{
            $from = (int)$_GET['pg'];
        }
         // And generate links with thumbnails
        for ($i=($from*$limit);($i!=$total) && ($i<($from*$limit)+$limit);$i++){
         // Check for a key in the list with the current value of $ i to avoid errors
        if(array_key_exists($i, $list)){
            echo "<td>
            <img class='port-img-ie' src='$path/$list[$i]' />
            </td>\n";
             $n++;
        if ($n == $limit_file){
            echo "</tr>\n";
             $n = 0;
        }}}
        }else{
            echo "$path not a directory";
        }
        ?>
    </tr>
</table>

Example.
http://nakome.16mb.com/portfolio

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: snippet portfolio

Hi! Noob question -- is it possible to generate albums?

Re: snippet portfolio

Sorry I'm not very good in php you can do is create a template from the gallery and include a snippet with a different folder path to the drawback is that you have to do yourself.

Look at this example at the end of the page.

http://nakome.16mb.com/

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

4 (edited by Samar Prit 2013-10-28 15:05:11)

Re: snippet portfolio

When coding a website, making use of existing code snippets can be a great time-saving practice. It could be your own snippets that you keep and re-use, or you can benefit by using snippets that have been shared by other developers.

Visit the links below:
stocks

stock watch