i have a webpage with a url going out.
I want to change the filename that the person will receive.
test - click here to download
<?php
header('Content-Disposition: attachment; filename="test.avi"');
?>
The problem is:
I receive the web page and not the file..
When i access the page, a download starts directly.. it's should wait for me to click on the "click here to download".
Also, the downloaded file, is only the actual source code of the page and not the file that i want to download..
Here is a screenshoot, better to explain than my words with my bad english :D
http://i.stack.imgur.com/Si9cP.png
Thanks.
It very simple.
You just need to add download attr to your tag like this:
<a href="http://downloadlink.com/Grizzly.avi" download>test - click here to download</a>
It will start downloading.
For reference
The Content-Disposition needs to go in the header for the file you are offering the user to download (i.e. the avi file in your example).
It doesn't go in the header for the HTML document with the link to the file.
Related
Community,
I would like to run a script when you click a link, but this shouldn't open in a new frame, that's why I added the following:
<iframe style="display:none;" name="target"></iframe>
<a href="script.php" target="target">
The script now executes without popping a blank page, joy. But I want the same link to open a PDF file.
<a href="pdf/cesar.pdf" target="_blank" > click here to download </a>
But now the PDF doesn't show, as the target frame is hidden. I can't seem to combine these two. Can someone help me out on this?
Cheers!
Cesar.
It sounds like you might be over-engineering this. Consider the high-level requirements:
The link needs to:
Execute PHP code
Open a PDF file
This sounds like two actions, but from the perspective of the client it's really only one action... open the PDF file. The rest is up to server-side code.
So create one link to perform that one action:
click here to download
As long as getPDF.php returns a PDF file, the client will never know the difference. What that PHP code does before returning that file is up to you. You can have all the code you want in that file, as long as the resulting response is returning the PDF file back to the client.
With the display none it will never show up, you probably should use jQuery, I'd added an ID to the "a"
<iframe style="display:none;" name="target"></iframe>
<a href="script.php" id="openPdf" target="target">
and when click:
$(document).on("click","#openPDF",function(){
$("iframe").css("display","block");
});
I want to create a email body that contains download link, when someone click on the download link, it will be immediately download.
But instead the following code open the image in new tab from the browser. How to solve this problem?
$message .= '<a download href="ip-address/img/feature-4.png">Download
Link</a>';**strong text**
p/s:I had tried force browser to download image files on click ,but it did not solve my problem.
Add download attribute to link, but this solution works in modern browsers only.
<img src="/path/to/image" />
I uploaded the .doc file using php code and saved it in a folder ,the path is stored in database.
When i tried to make a view of the doc file in a div ...a dialog box appears asking whether to save or openwith ..
I'm using wampserver ....I just tried like this
<iframe name="awindow" frameborder=2 width=580 height=440 src="www/siva_example/pdf/1_siva.doc"></iframe>
Any help regarding..
Is it possible to view .doc file in browser or i have to convert it to pdf format...
It's not possible to display a .doc[x] in HTML. You can try to convert the .doc[x] to HTML or to an image.
you can view doc file by adding this to your header at request time
<?php
header('Content-disposition: inline');
header('Content-type: application/msword');
// not sure if this is the correct MIME type
readfile('MyWordDocument.doc');
exit;
You could try using google docs for this, use the below code, it works perfectly for ppts, have not been able to test it for a doc yet
<iframe src="http://docs.google.com/gview?url=http://yourdomain.com/document.doc&embedded=true" style="width:550px; height:450px;" frameborder="0"></iframe>
Ofcourse you would have to update the url as per your program using PHP
I am working on a wordpress. I make a meta field for upload pdf file,pdf file upload sucessfully. Now i call meta value in href link for download the pdf file.But the problem is that it can open the file but not download.For this i search a code that is
<?php
header("Content-Disposition: attachment; filename=$event_flyer");
?>
$event_flyer is used for accessing meta value.
but its not working for specific href its just working for whole page on refresh.
If you want your pdf file to be downloadable by anyone who could browse your website just by clicking on links, then you can use the download attribute (for tags) which allows you to specify the linked resource :
Doc here : http://www.w3schools.com/tags/att_a_download.asp
Actually if you have a reader installed it will always open instead of downloading.
If you have hosted your wordpress on a live server then you can try to open link on a PC where PDF reader is not installed. It will download the file instead of opening.
You need more code, check this:
header("Content-disposition: attachment; filename=$pathtopdf");
header("Content-type: application/octet-stream");
readfile($pathtopdf);
i've created a php file which shows data from database:
http://www.eedmoe.gov.bd/report/app/webroot/files/uploaded/tenders/tender.php
But I want to download files. Report.doc, contact.txt, etc files are saving this folder:
http://www.eedmoe.gov.bd/report/app/webroot/files/uploaded/tenders/
I want that any visitor or user can download those files by clicking or save as. What should be the php function or code am I going to use?
Change the href attribute of the links to the filenames. To download 'contact.txt' for example use this link in your html:
contact.txt
You'll need no php for this.
You can also make a specific page to force download if you don't want it to be opened by the browser :
<?php header("Content-Type: application/force-download"); ?>
See Doc here