So, in another QUESTION, I got this answer:
$filename="filetodownload.xyz";
$cf = realpath("/non-webaccessible-folder/".$filename);
$file=$cf;
header('Content-Disposition: attachment; filename="' . basename($cf) . '"');
header("Content-Length: " . filesize($cf));
header("Content-Type: application/octet-stream");
readfile(realpath($cf));
I was able to get it working for my purposes by just using the top header line:
header('Content-Disposition: attachment; filename="' . basename($cf) . '"');
There are some questions I have about the whole solution though, to increase my understanding:
1. Is the purpose of using basename() simply to strip the path from the filename?
2. What is the purpose of realpath()? In my usage, it seems to make no difference whatsoever. Based on what I've found, it seems to just 'standardize' filepath inputs. Is that correct?
3. I don't seem to need the last three lines to make this work:
header("Content-Length: " . filesize($cf));
header("Content-Type: application/octet-stream");
readfile(realpath($cf));
Do I need them? What do they do? I should note that I'm testing just using localhost, in case that makes a difference.
Is there any kind of security considerations I should make when using this method for providing file downloads?