Quote:
Originally Posted by bigtunafan
Hey Codemonkey,
You believe you lost me at "php". I have the code copied to my text editor but from there I don't have a clue what to do. How do I link the eBook to the php file and so forth?
Php is something I've been wanting to learn but feel quite intimidated by the language. 
|
OK bigtuna, here we go....
So you understand exactly, we'll assume the e-book file is named "
e-book.pdf"
and your domain is called
bigtuna.com (for demonstration purposes only).
We will also assume that the html file (where you will put the link)
is called
download.html and all files will be in your website root or home directory.
1.) Copy the code I posted (in the php box) exactly as is to a text editor.
2.) Save the file locally (to your drive) as download_book.php
The file type should be Text Document or Text Document MS-Dos Format
3.) Close the text editor and look for the file you saved, it should be named download_book.php - if it's named download_book.php.txt just rename (take the .txt off)
4.) Now upload this file using a ftp (file transfer protocol) program (or however you normally do it) to the same location as your e-book (e-book.pdf)
also the same location as your original html file (download.html) where you will be putting the link
5.) Now add this link to download.html
<a href="http://bigtuna.com/download_book.php?file=e-book.pdf">Download e-book here</a>
6.) save download.html and ftp it to the website root of your server.
The following files should now be on your server at this location:
please adjust the domains and file paths to your situation.
It will work and Now to explain WHY it works...
As you can see the
<a href link is really calling download_book.php
but it's also passing a parameter
?file=e-book.pdf
We gave this parameter a reference name "
file" and
assigned the literal "
e-book.pdf" to it.
passing parameters through a URL link like this
is using http-get as opposed to http-post
NOTE: passing multiple parameters through the URL are normally separeted by & which should really be & this becomes an issue when trying to W3C validate document types (see w3c validation post) on this forum
The php interpreter recognizes the
<?php tag in the php file and starts processing until
?> which is a signal to stop.
the header commands tell what kind of file it is and how it should be handled notice the attachment reference, we give the filename by using the php code
.basename($_REQUEST['file'])
.basename will give you the filename without the full path
and
$_REQUEST['file'] is extracting the parameter with the reference name "file" from the passed variables.
$_GET could also be used
$_POST is how to extract passed data through posting
and $_SERVER is usually how a program knows things like what what you ip address is
$_SERVER['REMOTE_ADDR'] etc....
readfile($_REQUEST['file']); is again requesting the contents of parameter
named "file" and opening it and reading the file to the ouput buffer
we defined the output buffer in our header declarations so the file is an attachment and would stream down to the user.
The browser detects and identifies the stream and gives you the OPEN or SAVE dialog box!!
Whew....
That's all for now, let me know if you have trouble applying it to your situation.