Prevent link to file from downloading? Open instead?
Permalink 2 users found helpful
When editing text, you can select a piece of text, and click add link to file, but how do you prevent the file from always downloading. How can I a PDF file to open in the clients default pdf application, instead of downloading it?
Whatever happens, PDF files have to be downloaded in order to open on the person's machine. That person has to set what he wants to happen with PDF files. For example in Firefox under Tools, there's "PDF Downloads options" where they can set whether to open the file or save it or even open as HTML.
that is for normal people. you and me and everybody normal is pretty comfortable with this.
but imagine a client-idiot which wants the pdf to be opened in the same window and this is his requirement.
I have this problem now and I am searching for some workaround. pdfs are forced to be downloaded and I really need just a link to them, not to the download files controller, which forces them to download. any idea would be helpful.
but imagine a client-idiot which wants the pdf to be opened in the same window and this is his requirement.
I have this problem now and I am searching for some workaround. pdfs are forced to be downloaded and I really need just a link to them, not to the download files controller, which forces them to download. any idea would be helpful.
its been a while, but how your browser handle's PDF's is specific to your browser, isn't it? I dont remember a embed statement for PDF's or anything like that..
To add to discussion about PDF's downloading instead of just opening. I ahve checked my Firefox browzer sttings and they indicate that the PDF's should open in the Firefox browzer. I have setup a hyperlink to have the PDF file open in a new (_blank) tab or window but it still insists on asking me what to do. I.E. "You are attempting to open a file" dialogue. I have other websites not using Concrete5 and do not have a problem, the files just simply open a new tab and display the PDF just fine. Based on this I am concluding it must be a problem with Concrete5.
Does anyone have a resolution for this one? Is there some kind of setting I can turn on or off?
I'm having the same problem. For now I'm using 'www.scribd.com' to host my .pdf and then using the HTML block to post the code from 'scribd' this lets you display the pdf inline with a download and print link.
I am have the same requirement. I don't see anyone from the Concrete team weighing in. Surely someone has come up with a solution for this
it depends on the headers sent, c5 uses by default headers which force a download compared to the default in most browsers which is to view
If you simply enter a hyperlink directly to the full URL of the PDF file, it will open in your browser it you have that setting in your browser. This will work even if you have uploaded the PDF into the c5 file manager as long as you use the real URL. If course, if you replace the file, you will have to go update the URL manually.
If you use Add File to place the link on the page, or any of the other mechanisms for listing files from the file manager, then you will be forced into download.
I believe that concrete5 should offer the option of download or open.
If you use Add File to place the link on the page, or any of the other mechanisms for listing files from the file manager, then you will be forced into download.
I believe that concrete5 should offer the option of download or open.
Any chance of an answer on this?
I hate the thought of having to change links to about 50 pdf's to explicit hyperlinks and then change them back if this is ever fixed.
I hate the thought of having to change links to about 50 pdf's to explicit hyperlinks and then change them back if this is ever fixed.
Anybody?
There's basically two options in order to allow opening rather than forcing download:
1. Change your links. By default, they will say
http://www.mysite.com/index.php/download_file/1234...
Simply add /view_inline after /download_file, resulting in a link that looks something like this:
http://www.mysite.com/index.php/download_file/view_inline/1234...
2. Option two would be to create a file to override the core "download_file" single page. Simply copy /concrete/controllers/download_file.php to /controllers/download_file.php. In the first line of the view() function, add:
The only issue this will cause is that the user will not see a file name when the download prompt comes up. You can fix this by adding the following code to the view_inline() function after the line that says "header("Content-type: $mimeType");"
1. Change your links. By default, they will say
http://www.mysite.com/index.php/download_file/1234...
Simply add /view_inline after /download_file, resulting in a link that looks something like this:
http://www.mysite.com/index.php/download_file/view_inline/1234...
2. Option two would be to create a file to override the core "download_file" single page. Simply copy /concrete/controllers/download_file.php to /controllers/download_file.php. In the first line of the view() function, add:
$this->view_inline($fID);
The only issue this will cause is that the user will not see a file name when the download prompt comes up. You can fix this by adding the following code to the view_inline() function after the line that says "header("Content-type: $mimeType");"
$fv = $file->getApprovedVersion(); header('Content-disposition: attachment; filename="' . $fv->getFileName() . '"');
This is the best answer!
The simplest thing for me is to change the links, so I have not tried the other alternative. This allows me to have some PDF's that open and others that download.
Thanks jgarcia!
P.S. It would be nice if the C5 interface would allow this choice in the "Add File" command of the content block editor...
The simplest thing for me is to change the links, so I have not tried the other alternative. This allows me to have some PDF's that open and others that download.
Thanks jgarcia!
P.S. It would be nice if the C5 interface would allow this choice in the "Add File" command of the content block editor...
This solutions works great. I made one change though, I made it so that pdfs view inline in the browser (I see that as a bit more user friendly) instead of forcing the download. If you do a 'Download Linked File' or equivalent, the browser still knows the correct filename.
So I did everything in jgarcia's post, but changed the header line to:
(the difference being the word inline instead of attachment)
Cheers!
So I did everything in jgarcia's post, but changed the header line to:
header('Content-disposition: inline; filename="' . $fv->getFileName() . '"');
(the difference being the word inline instead of attachment)
Cheers!
If anyone is following this, I made a further change to the view_inline function.
In IE with Acrobat Reader, when a user does a 'Save As', that combination doesn't respect the filename sent in the header... it just makes up a filename to save the file as based on the url. (grrrr... all other browsers 'see' the intended filename in the header just fine).
So I read that a solution is to make sure the url has a real filename on it as well as a variable called file, so instead of:
index.php/download_file/view/94/1/
the url should be
/index.php/download_file/view/94/1/Car_Boot_Sale_Poster_2011.pdf?file=Car_Boot_Sale_Poster_2011.pdf
I looked at changing the way that C5 places the links in the content editor side of things, but that looked really fiddly, so I did a little bit of a hack to redirect the browser instead. It's not optimal because it ends up doing two page loads instead of one, but it does work well.
The change is the if conditioned redirect and a reshuffling of some of the other lines.
It does feel very hacky, so if anyone has any suggestions of how to improve this I'd been keen to see it.
In IE with Acrobat Reader, when a user does a 'Save As', that combination doesn't respect the filename sent in the header... it just makes up a filename to save the file as based on the url. (grrrr... all other browsers 'see' the intended filename in the header just fine).
So I read that a solution is to make sure the url has a real filename on it as well as a variable called file, so instead of:
index.php/download_file/view/94/1/
the url should be
/index.php/download_file/view/94/1/Car_Boot_Sale_Poster_2011.pdf?file=Car_Boot_Sale_Poster_2011.pdf
I looked at changing the way that C5 places the links in the content editor side of things, but that looked really fiddly, so I did a little bit of a hack to redirect the browser instead. It's not optimal because it ends up doing two page loads instead of one, but it does work well.
The change is the if conditioned redirect and a reshuffling of some of the other lines.
public function view_inline($fID) { $file = File::getByID($fID); $fp = new Permissions($file); if (!$fp->canRead()) { return false; } $mimeType = $file->getMimeType(); $fc = Loader::helper('file'); $fv = $file->getApprovedVersion(); if ($_GET['file'] == '') { header("Location: {$_SERVER['PHP_SELF']}" . $fv->getFileName() . '?file=' . $fv->getFileName() ); exit(); } $contents = $fc->getContents($file->getPath()); header("Content-type: $mimeType");
Viewing 15 lines of 19 lines. View entire code block.
It does feel very hacky, so if anyone has any suggestions of how to improve this I'd been keen to see it.
wow,
It's Very Nice Solution to view or download pdf files.
Hay man jgarcia your each and very reply is very useful to me
Thanks a lot.
It's Very Nice Solution to view or download pdf files.
Hay man jgarcia your each and very reply is very useful to me
Thanks a lot.