0

您好我正在尝试在 joomla 前端下载文件。在我的默认模板中,我为此使用 php 代码。代码是

<form><input type="button" value="Download Now" onClick="window.location.href='<?php echo $full;?>'">

$full完整路径在哪里= http://localhost/joomla/images/uploads/images22.jpeg。但这仅在浏览器中显示文件而不是下载它。我应该改变什么来使按钮点击下载?

4

2 回答 2

0

您需要强制文件下载..类似

$file = "image.jpg";
header('Content-Description: File Transfer');
header("Content-type: image/jpg");
header("Content-disposition: attachment; filename= ".$file."");
readfile($file);

我不确定您的文件的结构如何,但是如果您希望通过单击按钮来完成此操作,您可以像这样简单

<a href='download.php?file=k'>file</a> //or use a button with jquery.. or a reg submit button

然后做

if ($_GET ['file'])) //run code above adding the correct file name, also please remember 
that you will need to add some security here, I am not going to do it for you

这是最简单的方法。

于 2013-10-22T11:20:33.203 回答
0

我使用<iframe>标签从同一页面自动下载。

<iframe width="1" height="1" frameborder="0" src="[file location]"></iframe>
于 2013-10-23T05:12:56.733 回答