hi i'm trying to download a file in the joomla front end. in my default template i use php code for that. the code is
<form><input type="button" value="Download Now" onClick="window.location.href='<?php echo $full;?>'">
where $full
is the full path= http://localhost/joomla/images/uploads/images22.jpeg
. but this only displaying the file in the browser not downloading it. what should i change for making the button click to download ?
You need to force the file download.. something like
$file = "image.jpg";
header('Content-Description: File Transfer');
header("Content-type: image/jpg");
header("Content-disposition: attachment; filename= ".$file."");
readfile($file);
I am not sure how your file is structured, but if you want this done by clicking a button you can so something as simple as
<a href='download.php?file=k'>file</a> //or use a button with jquery.. or a reg submit button
and then do
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
This is the most simple way to do it.
我使用<iframe>
标记从同一页面进行了自动下载。
<iframe width="1" height="1" frameborder="0" src="[file location]"></iframe>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.