您好我正在尝试下载joomla前端的文件。在我的默认模板中,我使用PHP代码。代码是
<form><input type="button" value="Download Now" onClick="window.location.href='<?php echo $full;?>'">
其中$full
是完整路径= http://localhost/joomla/images/uploads/images22.jpeg
。但这只是在浏览器中显示文件而不是下载它。如果要点击下载按钮,我应该更改什么?
答案 0 :(得分: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
这是最简单的方法。
答案 1 :(得分:0)
我使用<iframe>
标记从同一页面自动下载。
<iframe width="1" height="1" frameborder="0" src="[file location]"></iframe>