当我点击每行的相应按钮时,所有其他按钮点击的iframe中会显示最新上传的pdf文件。 Iframe内容似乎没有刷新。这是我的代码:
<a onclick="opendoc(id)" data-id="<?php echo $value["doc_id"]; ?>"class="button blue" id="<?php echo $value["doc_id"]; ?>" data-toggle="modal" data-target="#myModal">
<!-- Modal -->
<div class="modal fade bd-example-modal-lg" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">View File</h4>
</div>
<div class="modal-body">
<div style="text-align: center;">
<iframe src="download.php?mode=view&id=<?php echo $value["document"];?>" id="myframe" style="border:5px solid grey;" width="800" height="600"></iframe>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
以下是javascript代码:
function opendoc(id)
{
var omyFrame = document.getElementById("myframe");
omyFrame.style.display="block";
alert(id);
}
并将文件显示到iframe, download.php如下
<?php
$file = './uploads/'.$_GET['id'];
$title=$_GET['id'];
header("Pragma: public");
// header('Content-disposition: attachment; filename='.$title);
//header('Content-disposition: inline');
header('Content-Disposition: inline; filename="' . $file . '"');
header('Content-type: application/vnd.openxmlformats-officedocument.word');
header('Content-type: image/jpeg');
header('Content-Type: application/octet-stream');
//header('Content-type: text/plain');
header('Content-type: application/pdf');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
?>