How do u create a download link?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rathlon
Forum Commoner
Posts: 45
Joined: Sun Nov 10, 2002 8:07 pm

How do u create a download link?

Post 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?
User avatar
bznutz
Forum Commoner
Posts: 58
Joined: Mon Dec 09, 2002 9:52 pm
Location: Here
Contact:

Post by bznutz »

huh?
Please be more specific.
Sect
Forum Newbie
Posts: 2
Joined: Wed Jan 29, 2003 4:09 pm

Post by Sect »

in php: echo "<a href=\"path to file\">file name</a>";


in HTML: <a href="path to file">File name</a>
fractalvibes
Forum Contributor
Posts: 335
Joined: Thu Sep 26, 2002 6:14 pm
Location: Waco, Texas

Post 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.
rathlon
Forum Commoner
Posts: 45
Joined: Sun Nov 10, 2002 8:07 pm

Post 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.
User avatar
bznutz
Forum Commoner
Posts: 58
Joined: Mon Dec 09, 2002 9:52 pm
Location: Here
Contact:

Post 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?
rathlon
Forum Commoner
Posts: 45
Joined: Sun Nov 10, 2002 8:07 pm

Post 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?
User avatar
bznutz
Forum Commoner
Posts: 58
Joined: Mon Dec 09, 2002 9:52 pm
Location: Here
Contact:

Post 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!
anndr0id
Forum Newbie
Posts: 3
Joined: Thu Jan 30, 2003 1:56 pm
Location: atlanta,ga

Post 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>
:)
redJag
Forum Newbie
Posts: 18
Joined: Fri Jan 31, 2003 12:17 am

Post 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).
Post Reply