jokerofsouls Posted October 10, 2008 Share Posted October 10, 2008 I wanted to know how i could make a submit button so one you click on it it will download a file. thanks for reading Quote Link to comment https://forums.phpfreaks.com/topic/127919-file-download/ Share on other sites More sharing options...
fanfavorite Posted October 10, 2008 Share Posted October 10, 2008 This shouldn't be in a PHP, but you could do it like: <input type="submit" name="submit" value="Download" onclick="location.href='downloadfile.zip';return false" /> Quote Link to comment https://forums.phpfreaks.com/topic/127919-file-download/#findComment-662309 Share on other sites More sharing options...
JasonLewis Posted October 11, 2008 Share Posted October 11, 2008 Or if you don't want to use JavaScript you can use PHP. <form action="download.php?file=file.zip" method="post"> <input type="submit" name="download" id="download" value="Download File" /> </form> download.php <?php $file = $_GET['file']; //Get the file. //You can do some error checking to see if the file exists, etc... header("Content-Disposition: attachment; filename=\"" . basename($file) . "\""); header("Content-Length: " . filesize($file)); header("Content-Type: application/octet-stream;"); readfile($file); ?> Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/127919-file-download/#findComment-662392 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.