This site has been immenselly helpful to me so far, but it seems I've finally come up against a problem. The question how to put a variable in a html input has been asked and awnsered before, but there's an issue I just can't seem to get to work.
<?php
if(isset($_POST['file_name'])){
$file = $_POST['file_name'];
header('Content-Disposition: attachment; filename="'.$file.'"');
readfile('uploads/'.$file);
exit();
}
?>
<form action="force_download.php" method="post" name="downloadform">
<input name= "file_name" type="hidden" value="test.txt" />
<input type="submit" value="Download">
</form>
The above code is being used to download the the text file "test.txt" One of many text files in my upload folder. My issue? How do I turn the value test.txt into a variable? A previous awnser I've read would be this:
<input type="hidden" name="file_name" value="<?php echo htmlspecialchars($file); ?>" />
The problem is that when I do that, it downloads force_download.php instead of any of my files.
I only started coding a few days ago, so yeah... sorry for the newbie question.