I want to make a pdf down-loadable which can't be directy accessed by an url.
This is how the link would look like
<a href="getFile.php?file=myfile.pdf" >Myfile</a>
and that is getFile.php
<?php
$file=$_GET['file'];
// Check if file really exists:
$files = array_diff(scandir('/www/secretPlace/'), array('.', '..'));
$show = (in_array($file,$files)) ? true : false;
if(!$show) exit();
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="' . $file . '"');
readfile( '/www/secretPlace/' . $file);
This works fine, as long as the pdf name does not include the &
symbol.
If I try
<a href="getFile.php?file=myfile & other stuff.pdf" >My Special File</a>
I would be able to download a file with the name, but I cant open it with a pdf reader. All programs tell me that the file is corrupted. How can I get open pdfs with readfile that have a &
symbol in their name?