Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is how I do it in PHP:</p> <pre><code>&lt;?php $fakeFileName= "fakeFileName.zip"; $realFileName = "realFileName.zip"; $file = "downloadFolder/".$realFileName; $fp = fopen($file, 'rb'); header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=$fakeFileName"); header("Content-Length: " . filesize($file)); fpassthru($fp); ?&gt; </code></pre> <p>Additionally, if you don't want anyone to have access to the file location, put a file named <code>.htaccess</code> into your download folder with only the contents:</p> <pre><code>deny from all </code></pre> <p>I changed the code a little. First when I say fake file name and real file name, the fake filename is the name that the downloader will download the file as, where the real filename is the name of the actual file in the download folder on your server.</p> <p>Also, I check to make sure the user is logged in and is able to download the file. If he chooses to download the file, a PHP file is called in a new tab (with the download code from above), then at the end of the file I have the line:</p> <pre><code>exit; </code></pre> <p>So when he clicks on the download link, a blank page pops up in a new tab quickly, then quickly exits and the download begins.</p> <p><strong>EDIT:</strong> The download link looks something like this:</p> <pre><code>&lt;a href="simpleDown.php?id=&lt;?php echo $_GET['id']; ?&gt;" target="_blank"&gt;Download!&lt;/a&gt; </code></pre> <p>Where <code>id</code> is the <code>id</code> of the download in the database, and in the download script from above I find the entry with that <code>id</code>, then get its real file name and the fake file name. You can do this without the database though.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload