Hallo,
Ik heb hier dus een gallery script die bestanden uit je dir haalt. Nu wil ik bij elk plaatje dat je hebt aangeklikt een vast nummer onder komt te staan. Dus stel je klikt de eerste thumbnail aan, dan komt er in het originele plaatje het nummer 1 te staan en bij de volgende nummer 2.
Ik heb al op PHP.net gezocht naar array en count, maar daar wordt ik niet veel wijzer uit.
Dit is een al reeds bestaand script dat ik wil modificeren:
Ik heb hier dus een gallery script die bestanden uit je dir haalt. Nu wil ik bij elk plaatje dat je hebt aangeklikt een vast nummer onder komt te staan. Dus stel je klikt de eerste thumbnail aan, dan komt er in het originele plaatje het nummer 1 te staan en bij de volgende nummer 2.
Ik heb al op PHP.net gezocht naar array en count, maar daar wordt ik niet veel wijzer uit.
Dit is een al reeds bestaand script dat ik wil modificeren:
PHP:
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
| <?php @error_reporting (E_ALL ^ E_NOTICE); /* --------------------------------------------------------------- * * USER SETTINGS * --------------------------------------------------------------- */ /* ** PAGE TITLE (text string) ** ** will appear at the top of the page ** **/ $page_title = "Babes"; /* ** LEFT CONTENT (text string) ** ** Link, description, graphic, etc - will appear in upper left ** **/ $left_content = "<a href=\"http://www.logoringtones.net\">Home</a>"; /* ** RIGHT CONTENT (text string) ** ** Link, description, graphic, etc - will appear in upper right ** **/ $right_content = ""; /* ** IMAGE SOURCE (text string) ** ** VIRTUAL PATH to the photo gallery images - NO trailing slash ** Images in this directory must be GIF and JPG files with lowercase '.gif' or '.jpg' extensions ** */ $image_dir = "babes"; /* ** NEXT PHOTO (text string) ** ** Defines what will be used as the "Next Photo". Can be image or text ** $next_photo = "Next"; will suffice, or get fancy with a custom graphic (and img tag) ** */ $next_photo = "Volgende"; /* USE_GIFS (bool) ** ** If 'use_gifs' is set to 'TRUE', thumnail images will be displayed ** below the large JPEG image ** ** NOTE: Except for their extension, gif files must be named IDENTICAL to JPGs. */ $use_gifs = true; /* ** COLUMNS (integer) ** ** below the large photo, is a grid of all other images in the photo ** gallery - $columns defines how many columns this grid will have ** */ $columns = 5; /* ** IMAGES (array) [OPTIONAL] ** ** Array of all image names in the photo gallery. For each ** item in this array, there should be a jpg and - if $use_gifs is true ** above - a gif. ** ** There are a couple ways to do this... ** ** [1] Manually create an array (without extensions) ** This is the least amount of work for PHP, and a little more work for you: ** $image = array( "image_1", "image_2", "image_3"); ** ** [2] Manually create an array by copying contents of the directory ** A little more work for PHP, easier for you: ** $image = array( "image_1.gif", "image_1.jpg", ** "image_2.gif", "image_2.jpg", ** "image_3.gif", "image_3.jpg"); ** ** [3] Automatically read your image directory ** Most work for PHP - easiest for you: ** LEAVE $image undefined (comment it out or delete it) ** ** Gif and jpg files must be named with ".gif" and ".jpg" extenstion (with lower case extenstion names) ** **/ //$image = array( "image_1", "image_2", "image_3"); /* --------------------------------------------------------------- * * DO NOT EDIT BELOW THIS LINE * --------------------------------------------------------------- */ if (!headers_sent()) { print("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n"); print(" \"http://www.w3.org/TR/html4/loose.dtd\">\n"); print("<html>\n"); print("<head>\n"); print(" <meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n"); print(" <title>PHP Photo Gallery</title>\n"); print("</head>\n"); print("<body>\n"); $print_footer = TRUE; } else { $print_footer = FALSE; } /* --------------------------------------------------------------- * * SETUP, DEFAULTS, and CHECK SETTINGS * --------------------------------------------------------------- */ $view = (isset($_REQUEST['view'])) ? $_REQUEST['view'] : ""; // Check Setup if (!isset($image_dir) || !$image_dir) { die("Setup Error:<br>The variable <b>\$image_dir</b> (in the 'USER SETTING' section) is not set."); } if (($image_dir[strlen($image_dir) - 1] == "/") || ($image_dir[strlen($image_dir) - 1] == "\\")) { die("Setup Error:<br>The variable <b>\$image_dir</b> (in the 'USER SETTING' section) should <b>not</b> end with a slash"); } if (!is_dir($image_dir)) { die("Setup Error:<br>The variable <b>\$image_dir</b> (in the 'USER SETTING' section) must be a directory."); } // Read all files in $image_dir if (!isset($image)) { $image = phppg_recursive_listdir($image_dir); } else { array_walk ($image, 'phppg_add_image_dir'); } if (!is_array($image) || !count($image)) { die("Setup Error:<br>There are no files in the image directory. You specify this direcory in the 'USER SETTINGS' secion as \$image_dir."); } // SECURITY CHECK // Requested $view must contain the REAL PATH of '$image_dir' if ($view) { $image_dir_path = realpath($_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . "/" . $image_dir); // REALPATH to user specified image directory $view_dir_path = dirname(realpath($_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . "/" . $view . ".jpg")); // REALPATH to the file we're supposed to be viewing if (!$image_dir_path || !$view_dir_path || !stristr($view_dir_path, $image_dir_path)) { die("BAD REQUEST<br>Please <a href=\"" . $_SERVER['PHP_SELF'] . "\">go back</a> and request another image"); } } // Remove ".gif" and ".jpg" extensions - only show unique images array_walk ($image, 'phppg_remove_extension'); $temp_image = array_unique($image); $image = array(); $i = 0; foreach ($temp_image as $v) { /* reset array keys */ $image[$i] = $v; $i++; } // Defaults if (!isset($columns) || !(int) $columns) $columns = 4; if (!isset($view) || !$view) $view = $image[0]; if (!isset($next_photo) || !$next_photo) $next_photo = "Next Photo"; if (!isset($page_title)) $page_title = ""; if (!isset($left_content)) $left_content = ""; if (!isset($right_content)) $right_content = ""; if (!isset($use_gifs)) $use_gifs = false; /* --------------------------------------------------------------- * * TOP NAV AND TITLE * --------------------------------------------------------------- */ if ($page_title || $left_content || $right_content) { ?> <table cellpadding="10" cellspacing="1" border="0" width="100%" align="center"> <tr bgcolor="#cccccc"> <td align="left" width="33%"><font size="-1"><?php echo $left_content; ?></font></td> <td align="center" width="33%"><font size="-1"><?php echo $page_title; ?></font></td> <td align="right" width="33%"><font size="-1"><?php echo $right_content; ?></font></td> </tr> </table> <br> <?php } /* --------------------------------------------------------------- * * DISPLAY - large JPEG IMAGE * --------------------------------------------------------------- */ //if ($view && (file_exists($image_path . $view . ".jpg"))) { if ($view && (file_exists($view . ".jpg"))) { $currKey = array_keys ($image, $view); $nextKey = $currKey[0] + 1; $prevKey = $currKey[0] - 1; if (!array_key_exists($nextKey, $image)) $nextKey = 0; if (!array_key_exists($prevKey, $image)) $prevKey = 0; ?> <table cellpadding="1" cellspacing="0" border="0" align="center"> <tr valign="top"> <td> </td> <td align="center"><a href="<?php echo $_SERVER['PHP_SELF'] . "?view=" . $image[$nextKey]; ?>"><?php echo $next_photo; ?></a></td> </tr> <tr valign="top"> <td height="150"> </td> <td align="center">[img]"<?php[/img].jpg" alt="" border="0"></td> </tr> </table> <?php } /* --------------------------------------------------------------- * * DISPLAY - thumnail GIFs * --------------------------------------------------------------- */ if ($use_gifs) { ?> <hr> <table cellpadding="10" cellspacing="0" border="1" align="center"> <tr> <?php $i = 0; if (!((int) $columns)) { $columns = 4; } foreach($image as $v) { ($i % $columns) ? $row = FALSE : $row = TRUE; if ($i && $row) { print("\t</tr>\n"); print("\t<tr>\n"); } print("\t\t<td valign=\"middle\" align=\"center\"><a href=\"" . $_SERVER['PHP_SELF'] . "?view=" . $v . "\">[img]\""[/img]</a></td>\n"); $i++; } ?> </tr> </table> <?php } /* --------------------------------------------------------------- * * FUNCTIONS * --------------------------------------------------------------- */ /** ** void phppg_remove_extension( (string) value, (string) key) ** ** Used by php function array_walk() to remove ".gif" and ".jpg" ** from array values ** ** @param value (string) array value passed by reference ** @param key (string) array key ** */ function phppg_remove_extension(&$value, $key) { $value = preg_replace(array("/.gif/i", "/.jpg/i"), "", $value); } /** ** void phppg_add_image_dir( (string) value, (string) key) ** ** Used by php function array_walk() to add the image_dir to all file names ** Only called if the user manually set up $image array (instead of reading ** the $image_dir directory with phppg_recursive_listdir() ** ** @param value (string) array value passed by reference ** @param key (string) array key ** */ function phppg_add_image_dir(&$value, $key) { global $image_dir; $value = $image_dir . "/" . $value; } /** ** array phppg_recursive_listdir( (string) base) ** ** Recursively looks through a directory and returns all items as an array ** ** @param base (string) base ** */ function phppg_recursive_listdir($base) { static $filelist = array(); static $dirlist = array(); if(is_dir($base)) { $dh = opendir($base); while (false !== ($dir = readdir($dh))) { if (is_dir($base ."/". $dir) && $dir !== '.' && $dir !== '..') { $subbase = $base ."/". $dir; $dirlist[] = $subbase; $subdirlist = phppg_recursive_listdir($subbase); } elseif(is_file($base ."/". $dir) && $dir !== '.' && $dir !== '..') { $filelist[] = $base ."/". $dir; //$filelist[] = $dir; } } closedir($dh); } $array['dirs'] = $dirlist; $array['files'] = $filelist; //return $array; return $filelist; } if ($print_footer) { print("</body>\n"); print("</html>\n"); } ?> |