implemented another way of finding next and prev (more kiss)
This commit is contained in:
parent
f20a06743f
commit
924290855d
1 changed files with 17 additions and 14 deletions
31
view.php
31
view.php
|
@ -6,24 +6,27 @@ $scriptPath = $_SERVER["SCRIPT_NAME"];
|
||||||
$quickDir = dirname($quickPath);
|
$quickDir = dirname($quickPath);
|
||||||
$realDir = "images$quickDir";
|
$realDir = "images$quickDir";
|
||||||
|
|
||||||
|
// get all images in an array
|
||||||
|
$images = array();
|
||||||
|
|
||||||
$files = scandir($realDir);
|
$files = scandir($realDir);
|
||||||
$size = count($files);
|
foreach ($files as $file) {
|
||||||
|
$ext = strtolower(substr($file, -4));
|
||||||
$pos = array_search(basename($quickPath),$files);
|
if ($ext == ".jpg" or $ext == ".png")
|
||||||
|
$images[] = $file;
|
||||||
$nextImage = '';
|
|
||||||
for ($next=$pos+1; $nextImage === '' and $next<$size ; $next++) {
|
|
||||||
$mime = mime_content_type("$realDir/$files[$next]");
|
|
||||||
if ($mime == "image/jpeg")
|
|
||||||
$nextImage = $files[$next];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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--) {
|
$nextImage = '';
|
||||||
$mime = mime_content_type("$realDir/$files[$prev]");
|
if ($pos > 0)
|
||||||
if ($mime == "image/jpeg")
|
$prevImage = $images[$pos-1];
|
||||||
$prevImage = $files[$prev];
|
if ($pos < sizeof($images))
|
||||||
}
|
$nextImage = $images[$pos+1];
|
||||||
|
|
||||||
$imageUrl = dirname($scriptPath)."/images$quickPath";
|
$imageUrl = dirname($scriptPath)."/images$quickPath";
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue