Ok, so I’m trying to create a download link generator on my site.
What I mean by that is this :
-
- the user writes “list X” and the site lists every file in a given directory
-
- every file has a number (from 0 to n)
-
- when the user types : “download 5” for example
-
- it redirects the user to a download script
-
- the script makes it so that the user has a download “box” that pops-up
I first thought that I could create an array with every file name and then use the position in that array for the “download X” command.
So that, when he redirects the user to the download script, the variable with the name of the file that the user wants to download is “POST”ed to the download script and the header is changed in consequence.
So here are my two questions :
1) – How do you change the download script according to the users input ?
2) – The input field is already used for other purposes with a “$_SERVER[‘PHP_SELF’]”, so I don’t know how to “POST” variables without a form ?
This is my simple download script :
<?php
header('Content-disposition: attachment; filename=huge_document.pdf');
header('Content-type: application/pdf');
readfile('huge_document.pdf');
?>
Thanks in advance !
Don’t make them type in anything. Make each download a link they click on. In the link’s URL you will have a query string with the download’s unique identifier. Something like this:
downloadscript.phpwould then get the ID from the$_GETsuperglobal and you can go from there (using an array as mentioned in your example):