Jump to content


Photo

downloads


  • Please log in to reply
10 replies to this topic

#1 PC Nerd

PC Nerd
  • Members
  • PipPipPip
  • Advanced Member
  • 1,122 posts
  • LocationAustralia

Posted 02 July 2006 - 12:24 AM

i want to create a download link and i dont know how to do it.  i simply want to put a pyhon prgoram that i have written opn my web site.  Can i do this with html or php.  wats the code for it ???????

can any one help me.

all help is much appreciated

#2 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 02 July 2006 - 12:26 AM

You just upload the file to your web server and you have the download link, if you wanna display the link just do this:
<a href="URL">words</a>

Replace the URL with the download link, and the words to any words (it could be the file name).

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#3 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 02 July 2006 - 12:42 AM

You simply do what hackerkts said, or if you're talking about keeping the file off the public web directory (private area), then you want to force a download. Read this topic:

http://www.phpfreaks....html#msg389027



#4 redarrow

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

Posted 02 July 2006 - 03:13 AM

if your  not using a database then do this ok

<a href="file_name.zip">donload my game</a>

Just remeber i am using a non database way and the file has to be a zip file and in the same folder as the
html code.

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

#5 PC Nerd

PC Nerd
  • Members
  • PipPipPip
  • Advanced Member
  • 1,122 posts
  • LocationAustralia

Posted 02 July 2006 - 03:22 AM

thanks guys, so i simply link to the file, eg

<a href = "../downloads/program.py">Download</a>

this will force the user to dowload the file program.py


???

ill try it noew

thanks again

#6 redarrow

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

Posted 02 July 2006 - 03:27 AM

to force downloads this is the correct method as posted link from toplay

<?PHP
ob_start();
$fname = 'http://www.example.com/test.txt';

header('HTTP/1.1 200 OK');
header('Content-Type: application/unknown');
header('Content-Disposition: attachment; filename=' . basename($fname));
header('Content-Transfer-Encoding: binary');

readfile($fname);

header('Content-Length: ' . ob_get_length());

ob_end_flush();

echo 'This will not show in browser or be in file';
?>

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

#7 PC Nerd

PC Nerd
  • Members
  • PipPipPip
  • Advanced Member
  • 1,122 posts
  • LocationAustralia

Posted 02 July 2006 - 03:51 AM

ok thanks.  can you walk me through wat the highlighted code does.  I dont quite understand wat some of the code does.  if you could that would be great

<quote>

<?PHP
ob_start();
$fname = 'http://www.example.com/test.txt';

header('HTTP/1.1 200 OK');
header('Content-Type: application/unknown');
header('Content-Disposition: attachment; filename=' . basename($fname));
header('Content-Transfer-Encoding: binary');

readfile($fname);

header('Content-Length: ' . ob_get_length());

ob_end_flush();

echo 'This will not show in browser or be in file';
?>

</quote>

i know it look really bad, but i always learn how to script things myself, not just copy others work.

#8 redarrow

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

Posted 02 July 2006 - 03:56 AM

just look up header php ok then lookup the code you dont understand ok.


research research lol................................

trust me your get the code more inbeded ok

good luck.
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

#9 heckenschutze

heckenschutze
  • Members
  • PipPipPip
  • Advanced Member
  • 257 posts
  • LocationAustralia

Posted 02 July 2006 - 03:59 AM

ob_start();
Turns on 'Output buffering', meaning everything you intend to output, will be captured in an internal buffer instead of being directly outputted.

header('HTTP/1.1 200 OK');
header('Content-Type: application/unknown');
header('Content-Disposition: attachment; filename=' . basename($fname));
header('Content-Transfer-Encoding: binary');
These are some HTTP/1.1 Protocol headers, you can read up on the HTTP/1.1 protcol here: http://www.w3.org/Pr...16/rfc2616.html

readfile($fname);
Is a PHP function that reads a file directly into your script, binary-safe. In other words the contents of that file will be placed into your script.

header('Content-Length: ' . ob_get_length());
This is another HTTP header, your sending over the length of your document, ob_get_length() returns the size of the internal output buffer in bytes.

ob_end_flush();
This outputs what is currently in the internal buffer then turns off output buffering.

HTH, Zac.






#10 PC Nerd

PC Nerd
  • Members
  • PipPipPip
  • Advanced Member
  • 1,122 posts
  • LocationAustralia

Posted 02 July 2006 - 04:07 AM

ok so how does this get turned into the dowload.  i am reaonably new to php and dont quite get where the link to the file goes.

thanks for your help

Pc Nerd

#11 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 02 July 2006 - 02:29 PM

ok so how does this get turned into the dowload.  i am reaonably new to php and dont quite get where the link to the file goes.

thanks for your help

Pc Nerd

When a user clicks on the link you did, then it will download the file. It's the simplest approach.

If you want to force a download to protect file location etc. then use code similar to what's provided. Please click on the link to the topic I provided and read it. It describes an approach (links.php & download.php). There's a link to a HTTP protocol book recommendation there too.

If you have the file saved locally, then use filesize() function to populate the Content-Length header and all the buffering stuff is not needed. It was used in that topic because the person had the file remotely using a full URL where filesize() doesn't work.

Good luck.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users