ajax-fotoalbum

Gesponsorde koppelingen

PHP script bestanden

  1. ajax-fotoalbum

« Lees de omschrijving en reacties

index.php

Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="nl" lang="nl">
    <head>
        <title> Fotoalbum </title>
        
        <style type="text/css">
            BODY, HTML {
                width: 100%;
                height: 100%;
                margin: 0;
                padding: 0;
                font-family: Arial;
                background: white;
                font-size: 12px;
            }
        
            #preload {
                display: none;
            }
            
            
            #maindiv, #mainframe, #mainframe TR, #mainframe TR TD {
                width: 100%;
                height: 100%;
            }
            
            #show {
                width: 300px;
                margin-left: auto;
                margin-right: auto;
            }
            
            .dir {
                display: block;
                margin: 1px;
                border: 2px solid black;
                border-width: 0 0 0 2px;
                background: #eee;
                padding: 2px;
                font-size: 16px;
                text-decoration: none;
                color: black;
                padding-left: 5px;
            }
            
            .dir:hover {
                background: #c0c0c0;
            }
            
            .file {
                display: block;
                font-size: 14px;
                text-decoration: none;
                color: black;
                background: #eee;
                margin: 1px;
                padding: 2px;
            }
            
            .file IMG {
                border: none;
                height: 12px;
                width: 12px;
            }
            
            .file:hover {
                background: #c0c0c0;
            }
            
            #big {
                border: 1px solid black;
            }
            
            #stats {
                border: 1px solid #c0c0c0;
                border-width: 1px 0 0 0;
            }
            
            LABEL {
                float: left;
                display: block;
                width: 150px;
            }
            
            #javascript {
                color: #c0c0c0;
            }
            
            INPUT {
                font-family: Arial;
                font-size: 12px;
            }
        </style>
        
        <script type="text/javascript">
            function showLoading() {
                getId('body').align = 'center';
                getId('body').innerHTML = 'Even aan het laden... <br /> <img src="loading.gif" alt="" />';
            }
        
            function createAjaxObject() {
                object = false;
                
                try {
                    object = new XMLHttpRequest();
                }
                catch(e) {
                    try {
                        object = new ActiveXObject('Msxml2.XMLHTTP');
                    } catch(e) {
                        object = new ActiveXObject('Microsoft.XMLHTTP');
                    }
                }
                
                return object;
            }
            
            function checkState(object) {
                if (object.readyState == 4) {
                    return true;
                } else {
                    return false;
                }
            }    
        
            
            function getId(id) {
                return document.getElementById(id);
            }
        
            window.onload = function() {
                <?php
                    if (!isset($_GET['link'])) {
                        ?>

                        request = createAjaxObject();
                        request.onreadystatechange = function() {
                            if (checkState(request)) {
                                getId('body').innerHTML = request.responseText;
                                getId('body').align = 'left';
                            }
                        }
                        request.open('GET', 'getLevel.php?level=&'+Math.random(), true);
                        request.send(null);
                        <?php
                    } else {
                        ?>

                        request = createAjaxObject();
                        request.onreadystatechange = function() {
                            if (checkState(request)) {
                                getId('body').innerHTML = request.responseText;
                                getId('body').align = 'left';
                            }
                        }
                        request.open('GET', 'showPic.php?pic=<?php echo htmlentities(strip_tags($_GET['link'])); ?>&'+Math.random(), true);
                        request.send(null);
                        <?php
                    }
                ?>

            }
            
            
            function loadLevel(level) {
                showLoading();
                
                request = createAjaxObject();
                request.onreadystatechange = function() {
                    if (checkState(request)) {
                        getId('body').innerHTML = request.responseText;
                        getId('body').align = 'left';
                    }
                }
                request.open('GET', 'getLevel.php?level='+level+'&'+Math.random(), true);
                request.send(null);
            }
            
            function loadPic(pic) {
                showLoading();
                
                request = createAjaxObject();
                request.onreadystatechange = function() {
                    if (checkState(request)) {
                        getId('body').innerHTML = request.responseText;
                        getId('body').align = 'left';
                    }
                }
                request.open('GET', 'showPic.php?pic='+pic+'&'+Math.random(), true);
                request.send(null);
            }
        </script>
        
    </head>
    <body>
        <div id="maindiv">
            <table id="mainframe"> <tr> <td valign="middle" align="center" id="body">
                <div id="javascript">Javascript is vereist om dit fotoalbum te kunnen bekijken.</div>
                Het fotoalbum is aan het laden, een moment geduld a.u.b. <br /> <img src="loading.gif" alt="" />
            </td> </tr> </table>
        </div>
        <div id="preload">
            <?php
                function preloader($map = 'pictures') {
                    foreach (glob($map.'/*') as $file) {
                        if (is_dir($file))
                            preloader($file);
                        else
                            echo '<img src="'.$file.'" alt="" />';
                    }
                }

                
                preloader();
            ?>

        </div>
    </body>
</html>


getLevel.php
Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
<?php
if (ereg('(..|http)',$_GET['level']) && (!ereg('^pictures',$_GET['level']) && !empty($_GET['level']))) exit('<div id="show">Er is een fout opgetreden.</div>');
?>


<div id="show">

<?php
function removeExtention($var) {
    $var = explode('.', $var);
    return $var[0];
}


$lvl = $_GET['level'];

$dirs = array();
$pics = array();

if (empty($lvl) || $lvl == 'pictures') {
    foreach (glob('pictures/*') as $file) {
        if (is_dir($file))
            $dirs[] = $file;
        elseif (ereg('(.jpg|.jpeg|.png|.gif)$', strtolower($file)))
            $pics[] = $file;
    }

    
    if (!empty($dirs)) {
        foreach($dirs as $file) {
            echo '<a href="#" onClick="javascript: loadLevel(\''.$file.'\');" class="dir">'.basename($file).'</a>';
        }

        echo '<br />';
    }

    
    if (!empty($pics)) {
        
        foreach ($pics as $file) {
            echo '<a href="#" onClick="javascript: loadPic(\''.$file.'\');" class="file"> <img src="'.$file.'" alt="" /> '.basename(removeExtention($file)).'</a>';
        }
    }
else {
        echo 'Er zijn geen foto\'s.';
    }
}
else {
    echo '<a href="#" onClick="javascript: loadLevel(\''.str_replace('/'.basename($file),'',$file).'\');" class="dir">Terug</a><br />';
    
    foreach (glob($lvl.'/*') as $file) {
        if (is_dir($file))
            $dirs[] = $file;
        elseif (ereg('(.jpg|.jpeg|.png|.gif)$', strtolower($file)))
            $pics[] = $file;
    }

    
    if (!empty($dirs)) {
        foreach($dirs as $file) {
            echo '<a href="#" onClick="javascript: loadLevel(\''.$file.'\');" class="dir">'.basename($file).'</a>';
        }

        echo '<br />';
    }

    
    if (!empty($pics)) {
        
        foreach ($pics as $file) {
            echo '<a href="#" onClick="javascript: loadPic(\''.$file.'\');" class="file"> <img src="'.$file.'" alt="" /> '.basename(removeExtention($file)).'</a>';
        }
    }
else {
        echo 'Er zijn geen foto\'s.';
    }
}

?>


</div>


showPic.php
Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
<?php
if (ereg('(..|http)',$_GET['pic']) && (!ereg('^pictures',$_GET['pic']) && !empty($_GET['pic'])) || empty($_GET['pic'])) exit('<div id="show">Er is een fout opgetreden.</div>');
?>


<div id="show">

<?php
function removeExtention($var) {
    $var = explode('.', $var);
    return $var[0];
}


$pic = $_GET['pic'];

$dirs = array();
$pics = array();

echo '<a href="#" onClick="javascript: loadLevel(\''.str_replace('/'.basename($pic),'',$pic).'\');" class="dir">Terug</a><br />';

$afmetingen = getimagesize($pic);

if ($afmetingen[0] > 300)
    $add = ' width="300px"';
else
    $add = '';

echo '<img id="big" src="'.$pic.'"'.$add.' id="image"/>';

echo '<br><br><div id="stats">';

echo '<label>Bestandsnaam:</label>'.basename($pic).'<br>';
echo '<label>Grootte:</label>'.round(filesize($pic)/1024/1024, 1).'MB ('.round(filesize($pic)/1024).'KB)<br>';
echo '<label>Afmetingen:</label>'.$afmetingen[0].'x'.$afmetingen[1].'<br>';
echo '<br>Link:<br><input onClick="this.select();" size="30" value="http://'.$_SERVER['SERVER_NAME'].'/index.php?link='.$pic.'" /><br>';

echo '</div>';
?>


</div>



loading.gif
Afbeelding

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.