File: index.php3

package info (click to toggle)
php3 1%3A3.0-2
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 6,512 kB
  • ctags: 6,320
  • sloc: ansic: 58,611; sh: 2,279; yacc: 1,090; php: 1,031; makefile: 911; cpp: 529; perl: 411; awk: 90; sql: 11
file content (95 lines) | stat: -rw-r--r-- 4,016 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?
    /* 
     * The thumbnail function uses the pnmscale program from
     * the popular Netpbm image manipulation tools package
     * to create a thumbnail of the given image.  If a thumbnail
     * already exists for the image, the function simply returns.
     */
    cfunction thumbnail($filename) {
        global $theight;
        /* Define where to find the various external binaries we need            */
        $djpeg = "/usr/local/bin/djpeg"; /* decompresses a jpeg to ppm format    */ 
        $cjpeg = "/usr/local/bin/cjpeg"; /* compreses a ppm to jpeg format       */
        $pnmscale = "/usr/local/netpbm/pnmscale"; /* scales a ppm image          */
        $giftopnm = "/usr/local/netpbm/giftopnm"; /* convert a gif to ppm format */
        $ppmtogif = "/usr/local/netpbm/ppmtogif"; /* convert a ppm to gif format */
        $ppmquant = "/usr/local/netpbm/ppmquant"; /* colour quantize a ppm image */

        $tdir = dirname($filename)."/thumbnails"; /* thumbnail directory         */
        if(!filetype($tdir)) {
            if(!@mkdir($tdir,0777)) {
                echo "Unable to create $tdir directory - check permissions<br>\n";
                return;
            }
        }
        $tfile = $tdir."/".basename($filename);   /* thumbnail file              */
        if(!filesize($tfile)) {
            if(ereg("\.gif$",$filename)) {  /* Look for .gif extension */
                exec("$giftopnm $filename | $pnmscale -height $theight | $ppmquant 256 | $ppmtogif -interlace > $tfile");
            } elseif(ereg("\.jpe?g",$filename)) { /* Look for .jpg or .jpeg extension */
                exec("$djpeg $filename | $pnmscale -height $theight |".
                     " $cjpeg -outfile $tfile");
            } else {  /* not a GIF or JPG file */
                return("");
            }
        }
        return($tfile);
    }

    /* If the album variable isn't set, show the album list */
    if(!$album) {
        $title = "Photo Albums";
        $page = "albums";
        include "include/header.inc";

        /* Get a list of the available albums */
        $albums = mysql_query("select filename,album,count(*) as num_albums from photos group by album");
        echo "<table align=center>\n";

        /* Loop through each album */
        while($row=mysql_fetch_row($albums)) {
            $row[1] = stripslashes($row[1]);
            $thumb = thumbnail($row[0]);
            if(strlen($thumb)) {
                echo "<tr><td><a href=\"$PHP_SELF?album=".urlencode($row[1]);
                $size = getimagesize($thumb);
                echo "\"><img src=\"$thumb\" border=0 $size[3]></a></td>";
                echo " <td><font size=+1><b>".$row[1]."</b></font><br>";
                echo "$row[2] photos<br></td></tr>\n";
            }
        }
        echo "</table>\n";
        mysql_free_result($albums);
    } 
    /* Ok, an album was selected, show the thumbnails for this album */
    else {
        $title = stripslashes($album);
        $page = "thumbnails";
        include "include/header.inc";
        $pics = mysql_query("select filename,text from photos where album='$album'");
        $album=stripslashes($album);
        echo "<center>\n";
        while($row=mysql_fetch_row($pics)) {
            if($photo==$row[0]) {
                $desc=stripslashes($row[1]);
            }
            $thumb = thumbnail($row[0]);
            if(strlen($thumb)) {
                echo "<a href=\"$PHP_SELF?album=".urlencode($album);
                $size = getimagesize($thumb);
                echo "&photo=$row[0]\"><img src=$thumb border=0 $size[3]></a>\n";
            }
            flush(); /* Force web server to flush buffer */
        }	
        echo "</center>\n";

        /* If a picture was selected as well, show the picture */
        if($photo) {
            $size=getimagesize($photo);
            echo "<center><img src=\"$photo\" $size[3]><br>$desc</center>\n";
        }
        mysql_free_result($pics);
    }

    include "include/footer.inc";
?>