【问题标题】:Opening a PDF file from within a table从表格中打开 PDF 文件
【发布时间】:2013-03-23 22:06:26
【问题描述】:

这是我的代码:

    foreach ($positions as $position) 
    {
        print("<tr>");
        print("<td>{$position["Post Date"]}</td>");
        print("<td>{$position["Description"]}</td>");
        print("<td>{$position["Link"]}</td>"); //shows location of the file
        print("<td>{$position["File Name"]}</td>");
        $file = rawurlencode($position["File Name"]);
        print("<td><input type=button name=open value='Open File'
        onclick=window.open(...);></td>"); // missing code to open pdf
        print("</tr>");
    }

?>

我正在创建一个表格,列出下载到特定目录 (localhost/pdfs/*.pdf) 的所有 pdf 文件。在以表格形式列出所有文件的页面上列出的文件名旁边,我有一个按钮,单击该按钮应打开该 pdf 文件。为什么是按钮?因为我前几天尝试将该文件名设置为链接,但没有成功……所以我有两个问题:

  1. 如果您对此有解决方案,更优雅的方法是通过链接打开该文件...
  2. 让我的按钮工作...文件可以使用标准 pdf 查看器打开,无需在浏览器中。

我们将不胜感激。

【问题讨论】:

    标签: php pdf button html-table


    【解决方案1】:

    正如你所看到的herewindow.open()是这样写的:

    var windowObjectReference = window.open(strUrl, strWindowName[, strWindowFeatures]);

    这意味着你的代码应该是

    print("<td><input type=button name=open value='Open File'
            onclick=\"window.open('{$position["Link"]}', 'pdf');\"></td>"); 
    

    【讨论】:

    • 对不起,这给了我 404 not found 错误...我可以用 pdf 查看器打开它吗?
    • 404 错误意味着{$position["Link"]} 给出的链接(我们不知道它的价值,它在你身边)是错误的。因为你的评论,我把它拿走了:print("&lt;td&gt;{$position["Link"]}&lt;/td&gt;"); //shows location of the file我猜这不是一个糟糕的位置;-)
    • 谢谢你,你当然是对的。这确实会在表/浏览器中显示文件位置,但由于某种原因浏览器不想打开该文件……这就是我最近几天一直在努力的事情。 ..因此我想知道我是否可以“强制”使用查看器而不是浏览器打开它。
    猜你喜欢
    • 2011-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-10
    • 2021-06-13
    • 1970-01-01
    相关资源
    最近更新 更多