Here is some PHP code I wrote for downloading a file from a remote server and saving it locally using the file's real name.
It tries to get the real file name using three methods:
- First by checking if the server returned the name of the original file to save as (using the content-disposition http header)
- By checking the content-type header that the server returned
- If all else fails then by the filename in the requested url.
I hope you find this useful.
Written by
Guy Malachi
Product-focused serial entrepreneur passionate about productivity, meaningful work, user experience, and building products that help people thrive.
Building HubThrive. Former CEO of Skylow/GuestsAI, Chief Product Officer at Showbox, CEO and cofounder of TalkSparks, iglloo and InterMatch, and Chief Geek at Conduit.
0 comments:
Post a Comment