07 August 2014

PHP code for fetching a remote file and saving it with the right file name

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:
  1. First by checking if the server returned the name of the original file to save as (using the content-disposition http header)
  2. By checking the content-type header that the server returned
  3. If all else fails then by the filename in the requested url.
I hope you find this useful.
Guy Malachi
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