我正在開發一個php web應用程序,其中文件列表(文本)以帶有按鈕的表格形式顯示,以查看,編輯或刪除每個文件。如何查看引導模式下的文本文件?
單擊任何文件的查看按鈕時,它應該顯示一個具有該特定文件內容的引導模式。到目前爲止,我還沒有做到這一點。
我將如何查看模態中的文件內容?謝謝 。
編輯:我強烈懷疑它與讀取目錄中文件內容的php代碼有關。我確定,我沒有做正確的事情。特別是,如何點擊特定的視圖按鈕來顯示特定的文件。任何有關PHP代碼的幫助將受到高度讚賞。
<?php
$path='/path/to/files';
$myDirectory=opendir($path);
if ($myDirectory==false)
{
echo "<br><br><div class='container'><div class='alert alert-danger text-center'><strong>Error!</strong> Failed to open Directory </div></div>\n";
break;
}
//Gets each entry
while($entryName=readdir($myDirectory))
{
$dirArray[]=$entryName;
}
closedir($myDirectory);
$indexCount=count($dirArray);
sort($dirArray);
//loops through the array of files
foreach ($dirArray as $value) {
# code...
$text=file_get_contents('/path/to/files/'.$value);
$content=str_replace("\n","<br>",$text);
$conn[]=$content;
}
for($index=0; $index < $indexCount; $index++)
{
$name=$dirArray[$index];
if ((strpos($name,'.') === 0) | $name == "." | $name == ".."){
continue;
}
print("
<tr>
<td><span></span><a href='$name'> $name <a></td>
<td>$path</td>
<td class='text-nowrap'><button type='button' class = 'btn btn-default' data-toggle='modal' data-target='#myModal' > View </button></td>
<td><button class = 'btn btn-default' data-toggle='modal' data-target='#edit'> Edit </button> </td>
<td><a href='delete.php?name=".$name."'><button class = 'btn btn-default' > Delete </button></a></td>
</tr>
");
}
?>
<div class='modal fade' id='myModal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel'>
<div class='modal-dialog' role='document'>
<div class='modal-content'>
<div class='modal-header'>
<button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>×</span></button>
<h4 class='modal-title' id='myModalLabel'></h4>
</div>
<div class='modal-body'>
<div> <?php
//print_r($conn)
foreach ($conn as $key => $value) {
echo $value;
}
?> </div>
<div>
</div>
</div>
<div class='modal-footer'>
<button type='button' class='btn btn-default' data-dismiss='modal'>Close</button>
</div>
</div>
</div>
</div>
請告訴我們您的代碼以及你在哪裏遇到困難這將幫助人們識別問題。歡迎來到StackOverflow! – plamut
謝謝@plamut。我已經包含了我的代碼。 – Worlalie
好!我希望你能得到你正在尋找的答案! – plamut