While rendering a PDF inside a frame in Firefox inline, the file name is ignored (click on save as after the PDF opens, and the name of the frame is shown in the save box, instead of the file name). I tried header('Content-Disposition: inline; filename=abc.pdf'); - it doesn't work. The same code works for attachment though, just doesn't work for inline. How to fix this?
This is in PHP, FF 15 and on windows.
You cannot set a file name while embedding the PDF in a frame or a browser tab
you change the title of the frame
you make another button for download where you force the user to download with your custom name
Related
When I add a download attribute in an anchor tag, it doesn't work at all. I've used it to create download link to download image from the website, but it opens the image instead of downloading. (I've tested this in chrome).
I've tried in different ways:
<a href="admin.jpg" download>Click here to download</a>
and Click here to download
<a> download attribute
If the HTTP header Content-Disposition is present and gives a different filename than this attribute, the HTTP header has priority over this attribute.
If this attribute is present and Content-Disposition is set to inline, chrome gives priority to Content-Disposition.
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.
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 need to display a (pdf,doc,docx,txt) documents inside an php web form with the ability to select a part of the document content and do some processing on it in the right click (like saving the selected content to DB)?
I try this way :-
<iframe src="http://docs.google.com/viewer?url=<?=urlencode($docx)?>&embedded=true" width="600" height="780" style="border: none;"></iframe>
But is show me as html
PHP can set the header information for a file and so you can display anything as file.php, loading the file.php you can then specify what it should be handled as- for example you can generate an image and output it as a jpeg file :
header('Content-Type: image/jpeg');
$img = LoadJpeg('bogus.image');
imagejpeg($img);
imagedestroy($img);
from http://php.net/manual/en/function.imagecreatefromjpeg.php example.
Using a similar method for setting the header content-type you can output PDF contents or DOC or whatever, by setting the header to the correct file type and loading the contents of the file with PHPs file_get_contents() ( http://php.net/manual/en/function.file-get-contents.php ) function, and outputting that to the browser / iframe.
Two things you can do:
Just link to the .pdf/etc. location on your server
Save the image of it as a .jpg and display that then put a link to download the pdf/whatever
I have a button on my page that links to the report.php page. What I want is that instead of clicking the button and see the php page, to click the button and open this report.php page as a PDF one.
Is this possible? How can I do it?
You can generate PDF and allow user to download it (if browser supports inline PDF display it will look as you want). Try mPDF. It generates PDFs from HTML and CSS.
Ofc its possible, you define headers and make a recommended file name istead of the extension php
<?php
// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
// The PDF source is in original.pdf
readfile('original.pdf');
?>
first example found on php.net
http://php.net/manual/en/function.header.php
assuming of course that the file your generating is compatible with pdf, you can find alot of pdf generators online but i would recommend using http://phpclasses.org
You can try this, HTML to PDF Converter. Convert your HTML to PDF and then display on screen, Here are examples.