【发布时间】:2018-06-10 09:40:55
【问题描述】:
如何通过单击Next 按钮和Previous 按钮浏览文件夹中的文件,然后在表格单元格中显示文件内容?
这是我的示例输出,但遗憾的是它对我不起作用:
这是我使用的代码:
<!DOCTYPE html>
<html>
<head>
<title>Browse Files</title>
</head>
<body>
<?php
$dir = '/xampp/htdocs/files';
$file = array_diff(scandir($dir), array('.','..'));
function showContent($fdata) {
$fopen = fopen($fdata,'r') or die ("Could not open file");
$content = fread($fopen,filesize($fdata)) or die("Could not read the file");
echo $content;
fclose($fopen);
}
?>
<table border = "1" cellpadding = "10" align = "center" width = "500">
<frame method = "post" action = "<?php echo $_SERVER['PHP_SELF']; ?>">
<tr>
<td>
<h3>File Contents: </h3> <br />
<?php
if (isset($_POST['next'])) {
for($i = 0; $i < sizeof($file); $i++) {
$path = $dir ."/". $file[$i];
showContent($path);
}
}
if (isset($_POST['previous'])) {
for($x = sizeof($file); $x > sizeof($file); $i--) {
$path = $dir ."/". $file[$i];
showContent($path);
}
}
?>
</td>
</tr>
<td align = "center">
<input type = "submit" name = "previous" value = "Previous">
<input type = "submit" name = "next" value = "Next">
</td>
</frame>
</table>
</body>
</html>
【问题讨论】:
标签: php arrays html css laravel-5.3