daydreamer Posted September 25, 2008 Share Posted September 25, 2008 how can i download a file using php, when the file link is like this: https://www.example.com/download/ It is just a text file, and when you go to the URL in your browser it gives you the option to either open it or download it. How can I download it using PHP and save it to my local hard drive? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted September 25, 2008 Share Posted September 25, 2008 Well, you can't make someone download something, can you? I mean, that'd be a pretty big security risk, no? All you can do is offer them the option to download a file or open/run it. If that's what you're after (wasn't sure, your question was a bit ambiguous) then google for php force download. You'll find plenty of information Quote Link to comment Share on other sites More sharing options...
efficacious Posted September 25, 2008 Share Posted September 25, 2008 well you might be able to use the "file" function of php to make a copy of the file. That would be just the same.. pretty much http://us3.php.net/manual/en/function.file.php Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 25, 2008 Share Posted September 25, 2008 well you might be able to use the "file" function of php to make a copy of the file. That would be just the same.. pretty much http://us3.php.net/manual/en/function.file.php That doesn't even relate to what he asked....Anyway, do you want a personal PHP script to download a file off a server, or do you want to offer a file for downloading? Quote Link to comment Share on other sites More sharing options...
daydreamer Posted September 25, 2008 Author Share Posted September 25, 2008 lol sorry for not being specific. I have my server, and want to download a file from another www server(not mine). this is for personal uses. I do not want to offer a download to anyone! any questions just ask! -thanks. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 25, 2008 Share Posted September 25, 2008 file_get_contents() or cURL would be your best bet. Quote Link to comment Share on other sites More sharing options...
daydreamer Posted September 25, 2008 Author Share Posted September 25, 2008 yeh i am trying curl at the moment, but the problem is that I do not have a direct download link. e.g the address is like: www.example.co.uk/download/ When i go to the page with my browser it offers me a download or open the file box. Seing as cURL is the "Client URL Library", I should be able to mimick my browser actions and download the file some how right? any suggestions? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 25, 2008 Share Posted September 25, 2008 Did you even try downloading it with cURL? It should work. Quote Link to comment Share on other sites More sharing options...
daydreamer Posted September 25, 2008 Author Share Posted September 25, 2008 yeh i have tried downloading it. I just get html code of the page, and not the actual file i need. Quote Link to comment 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.