Forum Moderators: phranque

Message Too Old, No Replies

Link to download file - not open it automatically

         

kaulbr

2:29 am on Jan 20, 2006 (gmt 0)

10+ Year Member



Right now I have a link on my web site for users to download a quicktime movie. If I want them to save it to their computer they have to right click on the link and 'save link as'. If they click on the link, it automatically opens the movie. I want to be able to just create a link that when they click on it, it asks them where they want to save the file (I don't want it to automatically open or them to have to right click on the link). Does this make sense? Does anyone know how I can create a link that will not try and open the quicktime movie but rather ask the user where they want to download it to on their local machine. Any help is appreciated.

celgins

4:14 am on Jan 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hmmmmm. That task has been a programming issue for many years. I have never seen any code that handles it perfectly. There are Javascript functions that will save the page, but none will cleanly save a .PDF, .MOV, or any media file.

Most browser functions that deal with the context menu (i.e. Open, Copy Shortcut, Save As, etc.), can only be invoked through a right-click. You can use the Javascript command "document.execCommand('SaveAs',null,'yourmovie.mov')", but again... that will only save the webpage.

If you're into programming, you may be able to tweak the document.execCommand to see if there is a way to accomplish this.

rocknbil

8:22 am on Jan 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can you do any programming at all, php, perl?

The browser is identifying the MIME type and managing it accordingly. Even if you change the extension, most browsers will "sniff out" the file itself and try to manage it.

What you need to do is "tell" the browser it's something else from the server side and munge up the content-type header - that is, give it a content-type you KNOW it can't possibly understand. A sample in perl:

## Store the filename in a variable:
$filename = 'yourfile.mov';

## open file and store in a variable (e.g., in memory)
open (FILE,"$filename");

## Not usually, but SOMETIMES, on some servers, you
## have to specify binary mode when reading the file.
## binmode FILE;

while (<FILE>) { $file .= $_; }
close (FILE);

## Can't remember why this must be one more byte than length!
$size = length( $file)+1;

## tell the browser it's an unknown type.
## this can be anything that is NOT a known
## type, ex "Content-type: blabla/debla";
print "content-type: bad/type\n"; # ONE return

print "Content-Length: $size\n"; # ONE return

# "filename" populates save box.
print "Content-Disposition: attachment; filename=$filename\n\n"; ## TWO returns flushes the content-type header and ...

print " $file"; ## deliver the goods.

This works for binary or ASCII data; pdf's, media, images, anything. When you munge the content header the browser's only option is to offer the requested file as a download. The above can be emulated in any server-side language. But I don't know what you can do in JS, never tried. :-)

kaulbr

1:58 pm on Jan 20, 2006 (gmt 0)

10+ Year Member



Thanks for your relies guys. I really don't do much programming though so I'm afraid that would be over my head. Was hoping there was a simple solution. Sounds like my only option is the ol' "Right Click Here" routine.

4string

2:15 pm on Jan 20, 2006 (gmt 0)

10+ Year Member



Put it in a zip file. That always works for me.

4

kamakaze

2:24 pm on Jan 20, 2006 (gmt 0)

10+ Year Member



Zip is a good idea but lets not forget about the non-savvy computer users who may not know that they have to download Winzip before they can utilize the download. That may discourage them from visiting the website again.

kaulbr

2:30 pm on Jan 20, 2006 (gmt 0)

10+ Year Member



I thought of that but exactly as the last post says, that makes it even more complicated. I post videos on my personal web site for family and friends and a lot of the people visiting are about as non-computer savy as they come. I embed the movies so that can watch them on my site but I also wanted to offer them a way to save the movie to their local machine as easily as possible. Why doesn't quicktime include a little 'save movie' option in the players menu? I read somewhere they used to have that option when you clicked the little down arrow on the right side of the movie controls.

kamakaze

2:45 pm on Jan 20, 2006 (gmt 0)

10+ Year Member



kaulbr - Unless I am mistaking you could create a self-extracting winzip file that only requires a double click from the user to extract the file. Someone correct me if I am wrong but I am pretty sure the person who is downloading the file does not even need to have WinZip installed for this feature.

kaulbr

2:54 pm on Jan 20, 2006 (gmt 0)

10+ Year Member



That wouldn't be too bad of an option. Is this somehwhat easy to create? I'll have to look into it more. Thanks.

4string

2:55 pm on Jan 20, 2006 (gmt 0)

10+ Year Member



Funny. I've had far more people complain to me that opening a pdf crashes their browser than trouble with zip files.

On all pdf files I always put "(right click to save to your hard drive)". I know that's not elegant, but you are also teaching them a new PC skill. That doesn't answer your automated question though. A self-extracting zip would work.

kamakaze

3:07 pm on Jan 20, 2006 (gmt 0)

10+ Year Member




That wouldn't be too bad of an option. Is this somehwhat easy to create? I'll have to look into it more. Thanks.

Yes its very easy to create. All you have to do is right click on the file you want to compress and select "Create self-extracting..." (I don't have it installed on my work pc but it is labeled someting like that) and it will create the compressed file in the same location as the original. That should be all that is required.

kaulbr

5:25 pm on Jan 20, 2006 (gmt 0)

10+ Year Member



What about the options you can use when you create a link like "parent" "blank" "self"... Would any of those do it?

celgins

6:07 pm on Jan 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Nah...those are anchor tags that either set or retrieve the name of a window that is the target for navigation.

Won't really help with file downloads.

I think packaging the .MOV files as .ZIP files, or creating .EXE files will do the trick. Not really a lot of options outside of that.

rocknbil

4:52 am on Jan 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My goodness. kaulbr you have a sticky message. :-)

kaulbr

2:23 pm on Jan 21, 2006 (gmt 0)

10+ Year Member



A sticky message? What does that mean?

kaulbr

2:25 pm on Jan 21, 2006 (gmt 0)

10+ Year Member



Never mind. I figured out what a sticky message is. Obvisouly my first ever.

spacerace

2:49 pm on Jan 21, 2006 (gmt 0)

10+ Year Member



The problem with a self extracintg zip is that it's an .exe

These files are being treated as the spawn of satan in most browsers now and XP SP2 blocks the loading of .exe's by default and fires up a warning message about unsafe content.

This will turn off more people than a right-click instruction!

- spacerace -