Download files from your server through browser – Simple PHP Script

-Below are give two small scripts, one is HTML and other is PHP.

-Paste below piece of code in a “input.html” file

<html>
<body>
<form action=”download.php” method=”post”>
<h2>Enter File Name </h2>
<input type=”text” name=”filename” size=”150″>
<input type=”submit” value=”submit”>
</form>
</body>
</html>

-Paste below piece of code in a “download.php” file

<?php
$file=$_POST['filename'];
header(‘Content-Description: File Transfer’);
header(‘Content-Type: application/php’);
header(‘Content-Disposition:attachment;filename=”‘.$file.’”‘);
readfile(‘/path/to/your/website_root_directory/‘.$file);
?>

-Save this above 2 files on your server’s root directory->and access them via browser.

For e.g – http://www.example.com/input.html

For Input Path – /app/etc/modules (the path after /path/to/your/website_root_directory/)

  • Luke

    This is a terrible idea. What’s stopping me from posting a filename of “../../../../etc/passwd”?