0

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 ?

user007
  • 61
  • 1
  • 2
  • 14
  • http://stackoverflow.com/questions/5648967/force-browser-to-download-image-with-javascript-window-open – Arun Unnikrishnan Oct 22 '13 at 06:19
  • sir, i dont want to go to any other page. the link u posted is using window.open and it pass to another page. since i'm working php in joomla component template i cant go to another page. i need to download file from the same page itself sir. – user007 Oct 22 '13 at 06:24
  • You can use window.location.href instead of window.open . Check this link to get an idea of how to create a download link. http://webprogram4beginners.blogspot.in/2011/02/how-to-make-download-link.html – Arun Unnikrishnan Oct 22 '13 at 06:43

2 Answers2

0

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.

xlordt
  • 521
  • 4
  • 15
0

i did automatic download from the same page by using <iframe> tag.

<iframe width="1" height="1" frameborder="0" src="[file location]"></iframe>
user007
  • 61
  • 1
  • 2
  • 14