MileHighLife Posted March 8, 2007 Share Posted March 8, 2007 I am able to get a list of files from a directory outside the web root but am unable to hyperlink to them to download. I've tried using fopen with no success. Can someone point me in the right direction? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/41797-download-file-outside-of-web-root-via-hyperlink/ Share on other sites More sharing options...
skali Posted March 8, 2007 Share Posted March 8, 2007 Do you have proper permission on the directory where you are trying to use fopen() to read file data? Quote Link to comment https://forums.phpfreaks.com/topic/41797-download-file-outside-of-web-root-via-hyperlink/#findComment-202694 Share on other sites More sharing options...
MileHighLife Posted March 8, 2007 Author Share Posted March 8, 2007 Do you have proper permission on the directory where you are trying to use fopen() to read file data? I do and am able to read and display the filenames on a page. I just can't figure out a way for users to download the files. Quote Link to comment https://forums.phpfreaks.com/topic/41797-download-file-outside-of-web-root-via-hyperlink/#findComment-202698 Share on other sites More sharing options...
skali Posted March 8, 2007 Share Posted March 8, 2007 You will have to fopen() the file and write the file content on the page, but before this you will have to send proper header that will denote the mime type of the file that you are writing on your page. Quote Link to comment https://forums.phpfreaks.com/topic/41797-download-file-outside-of-web-root-via-hyperlink/#findComment-202704 Share on other sites More sharing options...
MileHighLife Posted March 8, 2007 Author Share Posted March 8, 2007 You will have to fopen() the file and write the file content on the page, but before this you will have to send proper header that will denote the mime type of the file that you are writing on your page. They are .wav files. So I'm assuming I'd send a header like: header('Content-type: audio/x-wav); Then proceed with fopen()? Quote Link to comment https://forums.phpfreaks.com/topic/41797-download-file-outside-of-web-root-via-hyperlink/#findComment-202741 Share on other sites More sharing options...
ShogunWarrior Posted March 8, 2007 Share Posted March 8, 2007 Use readfile Quote Link to comment https://forums.phpfreaks.com/topic/41797-download-file-outside-of-web-root-via-hyperlink/#findComment-202742 Share on other sites More sharing options...
mjlogan Posted March 8, 2007 Share Posted March 8, 2007 header("Content-type: audio/x-wav"); header("Content-Disposition: attachment; filename=filename.wav"); readfile("/path/to/file/thisone.wav"); something along those lines i guess Quote Link to comment https://forums.phpfreaks.com/topic/41797-download-file-outside-of-web-root-via-hyperlink/#findComment-202745 Share on other sites More sharing options...
MileHighLife Posted March 8, 2007 Author Share Posted March 8, 2007 header("Content-type: audio/x-wav"); header("Content-Disposition: attachment; filename=filename.wav"); readfile("/path/to/file/thisone.wav"); something along those lines i guess AhhhH!!!!! Fabulous! You all rock. It works perfectly. Thanks. Jeff Quote Link to comment https://forums.phpfreaks.com/topic/41797-download-file-outside-of-web-root-via-hyperlink/#findComment-202785 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.