从“另存为浏览器”对话框中获取路径

时间:2012-06-24 23:56:55

标签: php javascript jquery

我正在开发一个使用jQuery和php的应用程序。我想通过“另存为”对话框提示用户,该对话框已包含我要将数据保存到的文件名。现在,有很多关于这个主题的帖子使用了以下内容:

header('Content-disposition: attachment;filename=whatever.dat');

我见过另一种技术:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns='http://www.w3.org/1999/xhtml'> 
  <head>
    <title>iframe downloader thingy</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    <script type="text/javascript">
      $(document).ready(function() {
        $('a#linky').click(function(){
          var iframe = document.createElement("iframe"); 
          iframe.src = 'http://cl.ly/120d44203F223O1X2T43/example_branding.zip'; 
          iframe.style.display = "none"; 
          document.body.appendChild(iframe);
          return false;
        });
      });
    </script>
  </head>
  <body>
    <a id="linky">Click to download</a>
  </body>
</html>

我需要将用户从“另存为”对话框中选择的整个路径返回给我,以便在php服务器脚本中进一步处理。我想要做的是获取一些MySQL数据并将该数据保存为逗号分隔的文本文件作为Outlook或Thunderbird邮件客户端的输入。

希望我已经清楚地解释了这一点。谢谢

爱德科恩

1 个答案:

答案 0 :(得分:0)

我会继续为你节省大量的时间 - 你绝对无法在浏览器的“另存为”对话框中访问这一小段文字。但是,您可以做的是从浏览器获取信息的完全相同的来源获取信息。

在给定可下载文件的URL的情况下,您应该能够编写一些PHP代码来获取下载URL为浏览器提供的“Content-disposition”标题。

相关问题