Page 1 of 1

How do u create a download link?

Posted: Wed Jan 29, 2003 2:53 pm
by rathlon
Can u create a php download link? Come to think of it, I don't really know how to create the link using straight html either...anyone?

Posted: Wed Jan 29, 2003 4:09 pm
by bznutz
huh?
Please be more specific.

Posted: Wed Jan 29, 2003 4:15 pm
by Sect
in php: echo "<a href=\"path to file\">file name</a>";


in HTML: <a href="path to file">File name</a>

Posted: Wed Jan 29, 2003 10:08 pm
by fractalvibes
Caveat:

If you are creating a link for people to actually download the source to a PHP script, you will need to rename and upload the file with a different extention - i.e. *.txt, not *.php.

Phil J.

Posted: Thu Jan 30, 2003 9:49 am
by rathlon
actually i'm just trying to figure out how to create a link so users can download files from me. Every form of the <a href"//////"></a> that I try doesn't seem to work. Pretty simple I'm sure (and do I ever feel like a dummy for asking) but I can't find anything on the web about this and oddly enough, none of my html books cover this...lol go figure.

Posted: Thu Jan 30, 2003 9:54 am
by bznutz
your path is probably incorect in the link.
if you file is in C:\inetpub\wwwroot\files\file.txt
and if your script or htm file is in the SAME directory, then the link should be
<a href="file.txt">File Link</a>
Remember that a link is "relative" to the path of the page displaying it.
What paths are the source and file in?

Posted: Thu Jan 30, 2003 10:01 am
by rathlon
actually it's all stored on a seperate drive (D: in this case). But the relative path is D:\www\graphics\pic1.jpg my link looks like
<a href="/pic1.jpg"> Download this file </a>
But when u click on the link it opens the file. I want it to prompt for a download. How do I do that?

Posted: Thu Jan 30, 2003 10:06 am
by bznutz
uh, you could either make the link point to a php script that does a binary push to the client, or you could use javascript that tells the browser to download the file, not open it. Of course, with javascript you will have to account for the force download command for all the different types of browsers and as far as php goes, I don't know the function that you would use to open a binary connection to the client to push the file.
I'm sure that you can find an answer at http://www.php.net

Cheers!

Posted: Thu Jan 30, 2003 3:27 pm
by anndr0id
an easier solution might be to put the pic in a ZIP file. those will automatically prompt the user to download with the simple anchor tag.
<a href=pic.zip>
:)

Posted: Fri Jan 31, 2003 12:17 am
by redJag

Code: Select all

<?php

header("Content-type: octet/stream");


header("Content-Disposition: attachment; filename=pic1.jpg");


readfile('pic1.jpg');
?>
Of course there is no guarantee this will work on every browser, but it works on the mainstream ones (barring the disabling of a given feature).