-1

好的,我又回来了:),但有一个新问题!

我正在尝试制作一个按钮,点击后,它将location.href对我的 download.php执行

巫术代码是:

<?
ob_start();
require_once 'includes/db.php';
require_once 'includes/init.php';
?>
<?php

     $file = "logs/".$_SESSION['username'].".txt";

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}
?>

我的其他代码巫术初始化按钮以下载 .txt 文件:

<?php 
        if (isset($_POST['clearBtn']))
        {
             ?>
               < location.href = 'download.php'>
              <?
            echo '<div class="nNote nSuccess hideit"><p><strong>SUCCESS: </strong>Logs have been downloaded</p></div>';
        }
        ?>
        <div class="widget">
          <div class="title"><img src="images/icons/dark/frames.png" alt="" class="titleIcon" /><h6>Logs</h6><form action = "" method="post" class="form">
          <input type="submit" style="margin-top: 4px; margin-right:4px;" value="Download Logs" name="clearBtn" class="dblueB logMeIn" /> 

我如何使这部分工作:

          ?>
          < location.href = 'download.php'>
          <?

感谢任何可以回答这个问题的人,我知道这可能是一个简单的问题,但我在任何地方都找不到答案,谢谢:)

4

3 回答 3

3

<a>标记没有名为的此类属性location.href。您正在考虑使用 JavaScript。

使用href

<a href="download.php">Text</a>
于 2013-06-27T07:59:30.810 回答
2

你可以试试这个。

<a href="Javascript:void(0)" onclick="window.location.href='download.php'"> Text </a>
于 2013-06-27T08:10:52.573 回答
1

要自动下载文件,请执行以下操作:

<?php if (isset($_POST['clearBtn'])): ?>
  <script type="text/javascript">window.location.href='download.php';</script>
  <div class="nNote nSuccess hideit"><p><strong>SUCCESS: </strong>Logs have been downloaded</p></div>
<?php endif; ?>
于 2013-06-27T08:03:15.453 回答