I'm having trouble modifying my PHP program. Originally, the program would download a particular file from a Unix box, which worked fine. Now I've modified it a little so the user can enter a file name to download.
Now it's not working, and I'm not sure why. It doesn't throw any errors that I can see; the page simply returns blank.
PHP version - 5.2.13
Apache - 2.0
Unix Box - HP-UX 11.11 (old version; latest is 11.31)
local PC - Windows XP Pro
Browser - IE 7, Mozilla
Code:
<html>
<body>
<?php
ob_start();
if(isset($_POST['name']))
{
$file = $_POST['name'];
echo "file is $file" ;
if(!file_exists($file))
{
die("file not found: " );
}
$name = basename($file);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$name.'"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
readfile($file);
exit;
}
else
{
echo " <form action='download1.php' method='post' enctype='multipart/form-data'>
<b> Enter the file name: </b><input type='text' name='name'>
<br> <br>
<button type='submit'> Upload </button>
</form>";
}
?>
</body>
</html>
What am I doing wrong?