![]() |
Link, which always offers to save/open....
Hi all
I have seen this, and now I need it myself. I need a link to some files, which should not be opened by the browser or plugins. I want a window to pop up and the user should choose the action. Several email services have this. I have been looking into, but not figured it out. Any ideas? BR Sonnich |
Re: Link, which always offers to save/open....
jodleren wrote:
> I need a link to some files, which should not be opened by the browser > or plugins. Google: HTTP Content-Disposition header -- Toby A Inkster BSc (Hons) ARCS Contact Me ~ http://tobyinkster.co.uk/contact Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux * = I'm getting there! |
Re: Link, which always offers to save/open....
On Mar 13, 5:18 pm, Toby A Inkster <usenet200...@tobyinkster.co.uk>
wrote: > jodleren wrote: > > I need a link to some files, which should not be opened by the browser > > or plugins. > > Google: HTTP Content-Disposition header You could be a little more specific... I found something and came up with: <?php $file=$_GET['file']; header('Content-type: application/force-download'); header("Content-Disposition: attachment; filename=\"$file\""); readfile($file); ?> Though, this opens a window (when I use this from another link), is there a way to avoid the browser window? BR Sonnich Please CC to sonnich_at_hot_._ee |
Re: Link, which always offers to save/open....
jodleren wrote:
> Toby A Inkster <usenet200...@tobyinkster.co.uk> wrote: > >> Google: HTTP Content-Disposition header > > You could be a little more specific... > I found something Firstly, I was clearly sufficiently specific, in that it lead you to an answer. Secondly, I couldn't be very much more specific than I was, as you didn't mention any details of your hosting situation in your original post. (Operating system, server software, scripting languages, level of access, etc.) > and came up with: [...] > header('Content-type: application/force-download'); Replace that line with a real content type. For example, if the file is a PDF, then the Content-Type should be "application/pdf". If it's a JPEG, then "image/jpeg". If you are really unable to determine the correct content type, use "application/octet-stream". Using made-up content types like the one you've used above may seem to be "convenient", but it harms the web as a whole. -- Toby A Inkster BSc (Hons) ARCS Contact Me ~ http://tobyinkster.co.uk/contact Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux * = I'm getting there! |
Re: Link, which always offers to save/open....
> > and came up with:
> [...] > > header('Content-type: application/force-download'); > > Replace that line with a real content type. For example, if the file is a > PDF, then the Content-Type should be "application/pdf". If it's a JPEG, > then "image/jpeg". If you are really unable to determine the correct > content type, use "application/octet-stream". > > Using made-up content types like the one you've used above may seem to be > "convenient", but it harms the web as a whole. Since I can have _any_ file, where is there an overview of those or trick to get them? And since I open this from another window, is the a way to have a link, which goes directly to the open/save dialog. That is what I really need. BR Sonnich |
Re: Link, which always offers to save/open....
jodleren wrote:
>>> and came up with: >> [...] >>> header('Content-type: application/force-download'); >> Replace that line with a real content type. For example, if the file is a >> PDF, then the Content-Type should be "application/pdf". If it's a JPEG, >> then "image/jpeg". If you are really unable to determine the correct >> content type, use "application/octet-stream". >> >> Using made-up content types like the one you've used above may seem to be >> "convenient", but it harms the web as a whole. > > Since I can have _any_ file, where is there an overview of those or > trick to get them? > > And since I open this from another window, is the a way to have a > link, which goes directly to the open/save dialog. That is what I > really need. This question gets ask quite often, a a specific media is handled by the browser (open in the browser, open directly by the app or download) is browser setting so if the user has set it to open in the browser there is not much you can do about it. -- Take care, Jonathan ------------------- LITTLE WORKS STUDIO http://www.LittleWorksStudio.com |
Re: Link, which always offers to save/open....
On Mar 13, 9:04 pm, Toby A Inkster <usenet200...@tobyinkster.co.uk>
wrote: > jodleren wrote: > > Toby A Inkster <usenet200...@tobyinkster.co.uk> wrote: > > >> Google: HTTP Content-Disposition header > > > You could be a little more specific... > > I found something > > Firstly, I was clearly sufficiently specific, in that it lead you to an > answer. > > Secondly, I couldn't be very much more specific than I was, as you didn't > mention any details of your hosting situation in your original post. > (Operating system, server software, scripting languages, level of access, > etc.) > > > > > and came up with: > [...] > > header('Content-type: application/force-download'); > > Replace that line with a real content type. For example, if the file is a > PDF, then the Content-Type should be "application/pdf". If it's a JPEG, > then "image/jpeg". If you are really unable to determine the correct > content type, use "application/octet-stream". Would there be a problem with getting the extension of the file and using it, such as: $ext = get_extension_of_file; header("Content-type: application/$ext"); > > Using made-up content types like the one you've used above may seem to be > "convenient", but it harms the web as a whole. What do you think about this? header("Content-Disposition: attachment; filename=\"$file\""); Is there a place where headers are listed? I could use that now BR Sonnich |
Re: Link, which always offers to save/open....
On Mar 14, 4:57 pm, "Jonathan N. Little" <lws4...@centralva.net>
wrote: > jodleren wrote: > > And since I open this from another window, is the a way to have a > > link, which goes directly to the open/save dialog. That is what I > > really need. > > This question gets ask quite often, a a specific media is handled by the > browser (open in the browser, open directly by the app or download) is > browser setting so if the user has set it to open in the browser there > is not much you can do about it. Well... I am playing around with this again... my mail, www.hot.ee, has a way of doing it... but I have a feeling that they do it in some other way. Also, I recall lately, a window, which opens, then is closes/dialog opens, so only the dialog remains... There is a way out there... BR Sonnich |
Re: Link, which always offers to save/open....
jodleren wrote:
> On Mar 13, 9:04 pm, Toby A Inkster <usenet200...@tobyinkster.co.uk> > wrote: > >>jodleren wrote: >> >>>Toby A Inkster <usenet200...@tobyinkster.co.uk> wrote: >> >>>>Google: HTTP Content-Disposition header >> > Would there be a problem with getting the extension of the file and > using it, such as: > $ext = get_extension_of_file; > > header("Content-type: application/$ext"); The MIME type doesn't always (or even usually) match the file extension. >>Using made-up content types like the one you've used above may seem to be >>"convenient", but it harms the web as a whole. > > What do you think about this? > header("Content-Disposition: attachment; filename=\"$file\""); You'd also need to set the content-type to something nasty[1]. Please don't. > Is there a place where headers are listed? Google is your friend. Well, it's *our* friend, but you could use it too. Take a look at http://www.w3schools.com/media/media_mimeref.asp. I cannot vouch for the veracity of the content in that table, since www.w3schools.com isn't always accurate, but it will give you an idea of what you're dealing with. Note especially the links at the top of the page, leading you to the RFC (Request For Comment) documents which are the source of this information. [1]http://www.onjava.com/pub/a/onjava/excerpt/jebp_3/index3.html -- john |
Re: Link, which always offers to save/open....
On Mar 13, 10:56 am, "jodleren" <sonn...@hot.ee> wrote:
> I have seen this, and now I need it myself. > I need a link to some files, which should not be opened by the browser > or plugins. I want a window to pop up and the user should choose the > action. This is my choice. You don' t have any say in what I do with the file. |
| All times are GMT. The time now is 10:05 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.