Я предполагаю, что ваши данные CSV-файла представляют собой массив имен файлов, разделенных новой строкой, как показано ниже:
some-img-01.jpg
img-02.jpg
img-05.jpg
....
Пожалуйста, проверьте следующие коды.
Я реструктурировал код для передачи состояния (если оно существует из предыдущего поста) между загрузками каждой страницы. Здесь я спроектировал цикл: от первого, если доходит до конца, и до следующего нажатия или переход до последнего, если предыдущий нажимается из первой позиции. Вы можете отключить эту функцию, закомментировав соответствующие строки (проверьте комментарии).
<?php
$current_index = isset($_POST['current_index'])? intval($_POST['current_index']) : 0;
$fp = fopen('imgname.csv', 'r');
$line = fread($fp, filesize('imgname.csv'));
fclose($fp);
$item = explode("\n", $line);
$sizecsv = sizeof($item);
$current_index = isset($_POST['current_index'])? intval($_POST['current_index']) : 0;
if ($current_index >= $sizecsv) $current_index = ($sizecsv - 1);
if ($current_index < 0) $current_index = 0;
if (isset($_POST['next'])) {
$current_index++;
// If reached end of the list, then clicked next, the index starts from firt again.
// If you dont need this feature, then can comment the following line.
if ($current_index >= $sizecsv) $current_index = 0;
}
if (isset($_POST['previous'])) {
$current_index--;
// If the indexin first image, but clicked the Previous button, then the index goes to last element.
// If you dont need this feature, then can comment the following line.
if ($current_index < 0) $current_index = ($sizecsv - 1);
}
if (isset($_POST['first'])) $current_index = 0;
if (isset($_POST['last'])) $current_index = ($sizecsv - 1);
?><!DOCTYPE html>
<html>
<head>
<title>Your Album</title>
</head>
<body>
<form method="post">
<input type="text" name="current_index" value="<?php echo $current_index;?>"/>
<input type="submit" name="first" value="FIRST"/>
<input type="submit" name="previous" value="PREVIOUS"/>
<input type="submit" name="next" value="NEXT"/>
<input type="submit" name="last" value="LAST"/>
<input type="submit" name="dele" value="DELETE"/>
</form>
<br>
<img src="images/<?php echo $item[$current_index];?>" width="250px"/>
<br>, Image No: <?php echo ($current_index + 1);?>
</body>
</html>