projects
/
bizou.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
f20a067
)
implemented another way of finding next and prev (more kiss)
author
Marc MAURICE
<dooblempub@positon.org>
Thu, 7 Oct 2010 22:27:29 +0000
(
00:27
+0200)
committer
Marc MAURICE
<dooblempub@positon.org>
Thu, 7 Oct 2010 22:27:29 +0000
(
00:27
+0200)
view.php
patch
|
blob
|
history
diff --git
a/view.php
b/view.php
index
d6d45bd
..
1b38962
100644
(file)
--- a/
view.php
+++ b/
view.php
@@
-6,24
+6,27
@@
$scriptPath = $_SERVER["SCRIPT_NAME"];
$quickDir = dirname($quickPath);
$realDir = "images$quickDir";
$quickDir = dirname($quickPath);
$realDir = "images$quickDir";
-$files = scandir($realDir);
-$size = count($files);
-
-$pos = array_search(basename($quickPath),$files);
+// get all images in an array
+$images = array();
-$nextImage = '';
-for ($next=$pos+1; $nextImage === '' and $next<$size ; $next++) {
- $mime = mime_content_type("$realDir/$files[$next]");
- if ($mime == "image/jpeg")
- $nextImage = $files[$next];
+$files = scandir($realDir);
+foreach ($files as $file) {
+ $ext = strtolower(substr($file, -4));
+ if ($ext == ".jpg" or $ext == ".png")
+ $images[] = $file;
}
}
+// find the image position
+$pos = array_search(basename($quickPath), $images);
+if ($pos === false) die("Image not found");
+
+// get prev and next images
$prevImage = '';
$prevImage = '';
-for ($prev=$pos-1; $prevImage === '' and $prev>=0 ; $prev--) {
- $mime = mime_content_type("$realDir/$files[$prev]");
- if ($mime == "image/jpeg")
- $prevImage = $files[$prev];
-}
+$nextImage = '';
+if ($pos > 0)
+ $prevImage = $images[$pos-1];
+if ($pos < sizeof($images))
+ $nextImage = $images[$pos+1];
$imageUrl = dirname($scriptPath)."/images$quickPath";
$imageUrl = dirname($scriptPath)."/images$quickPath";