Jump to content


Photo

How do I create "Do you want to run or save this file?" links?


  • Please log in to reply
14 replies to this topic

#1 Stuph

Stuph
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 03 September 2006 - 03:34 AM

Hello everyone,

I was just wondering if someone could please tell me how I can get one of those links on webpages so that when you click on it (in IE) it says "Do you want to run or save this file?"

I'm sure you know what I'm talking about, they normally say stuff like 'Click here to download...' Download.com is full of them.

If anybody knows how to do it in JavaScript or PHP then can you please tell me.

Thanks,
Ronanx


La la la noob.

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 03 September 2006 - 03:37 AM

its a link with an images one goes to a .exe and the other uses a zip in the link.

this is html
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 Stuph

Stuph
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 03 September 2006 - 03:46 AM

I don't really understand what you're saying.

Basically I want a link on my webpage (either HTML or PHP) that says 'Click here to download the MP3'.

And then when a user clicks the on the link I want it to come up with the "Do you want to run or save this file?" box. Then they can either listen to the MP3 by clicking 'Run' or download it by clicking 'Save'.

I've seen other people do it using some kind of PHP code but I haven't been able to view the source code.

Thanks again,
Ronanx
La la la noob.

#4 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 03 September 2006 - 03:49 AM

Uhm I forgot exactly how to do it but it involves headers...
Why doesn't anyone ever say hi, hey, or whad up world?

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 03 September 2006 - 03:54 AM

http://www.phpfreaks...ic,95433.0.html
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 Stuph

Stuph
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 03 September 2006 - 03:59 AM

Ok thanks guys thats all looks very promising, but how do I use it in real life terms?

I mean how, where and why would this work?

Cheers,
Ronanx
La la la noob.

#7 donturo

donturo
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 03 September 2006 - 10:32 AM

You can do this in your .htaccess file

You can use this code:


AddType application/octet-stream txt

This will make all links to txt files a direct download link....

Good luck!

#8 Stuph

Stuph
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 03 September 2006 - 09:59 PM

Hey thanks,

That code also looks quite helpful but I still don't know how to use it. I kind of understand the whole .htaccess thing but it doesn't seem to work.

I mean I'm not even sure if my web server is Apache PHP or not, and I don't know if that even matters.

Could someone please explain it in layman's terms for me. I'm so confused.

Cheers,
Ronanx

I feel like such a noob :P.
La la la noob.

#9 radar

radar
  • Members
  • PipPipPip
  • Advanced Member
  • 645 posts
  • LocationSLC

Posted 03 September 2006 - 10:05 PM

AddType application/octet-stream txt

is going to be your best bet...  though in your case it would be

AddType application/octet-stream mp3

I believe..  in your root folder on your host you should have a .htaccess file.. open this up add that in there and all mp3's should pop up that do you want to run or save dialog that you speak of.  that is unless the person has download accelerator plus -- then it'll just download it regardless..

#10 Stuph

Stuph
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 03 September 2006 - 10:13 PM

Ok thanks I will try it.

Would it matter if the MP3 file wasn't in the same directory or domain?

Cheers,
Ronanx
La la la noob.

#11 radar

radar
  • Members
  • PipPipPip
  • Advanced Member
  • 645 posts
  • LocationSLC

Posted 03 September 2006 - 10:43 PM

No it shouldn't matter at all..  Give it a shot if it doesnt work let us know we'll help figure something out.

#12 Stuph

Stuph
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 04 September 2006 - 05:55 PM

Well I've tried it, but it doesn't seem to make any difference.

I've put the .htaccess file in the highest directory that I can reach on my server but I don't think it's the top one, it's just the 'www' folder.

Basically I think my server is like this:

ftp://  ->  subdomain.domain.com  ->  home  ->  www  ->  subdomain.domain.com  ->  index.htm

When I log in it goes to the 'www' folder. And I can't go higher.

I don't really know how all this stuff works.

My .htaccess file says this (and only this):

AddType application/octet-stream mp3

Much help required :P.

Thanks,
Ronanx

Edit: The files permissions are '-rwxr-xr-x' if that means anything.
La la la noob.

#13 mariocesar

mariocesar
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts

Posted 07 September 2006 - 09:24 PM

hello, I have a page with little pictures of word documents, and a directory with the word documents (templates), I want our customers to have the choice to download the template when they click the little picture.
Thanks

#14 Stuph

Stuph
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 12 September 2006 - 10:22 PM

Help?
La la la noob.

#15 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 13 September 2006 - 02:23 PM

If you want it to give the user the option to save the file or open the file then you need to use headers like this:

<?php
	if(file_exists($the_file)) {
		if(filesize($the_file) == $fs) {
			$dl++;
			$qry = "UPDATE support_files SET downloads = '{$dl}' WHERE file_id = '{$uid}'";
			$query = mysql_query($qry) or die ("MySQL Error: <br />{$qry}<br />". mysql_error());
			header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
			header("Content-Type: {$ft}");
			header("Content-disposition: attachment; filename={$fn}");
			header("Content-Length: {$fs}");
			header("Content-Transfer-Encoding: binary");
			readfile($the_file);
			exit();
		} else {
			$message .= "<p>The file size is incorrect. Please notify the 
				<a href=\"mailto:support@.com\">Support</a> team about this.</p>\n";
		}
	} else {
		$message .= "<p>That file could not be located.  Please notify the 
			<a href=\"mailto:support@.com\">Support</a> team about this.</p>";
	}
?>

Also note when using headers your file size has to be correct or it will corrupt the file.  If any text output is echo'd before the file is downloaded the echoing text will be added to the header of the file corrupting it too. This is what I have have found when people were complaining about corrupted downloads ;)






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users