I've created a search form where the user would input the image code and when searched it will let the user download the file. Below is my code
<html>
<head>
<title>Search Contacts</title>
</head>
<body>
<h3>Search Client File</h3>
<form method="post" action="#" id="searchform">
Type the File Code:<br><br>
<input type="text" name="fcode">
<br>
<input type="submit" name="submit" value="Search">
</form>
<?php
$filecode=$_POST["fcode"];
if (!empty($filecode))
{
$file="/var/www/website/$filecode.pdf";
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
}
else
{
echo "No Results";
}
?>
</body>
</html>
The problem is that the downloaded file is unable to be viewed, or unviewable, what seems to be the problem with my code?