Using cURL (PHP's client URL extension) to download a file programmatically.
Hi All,
Here is a simple function using cURL to download a remote file. My goal here
was to access a remote wav file hosted on another server and import it into my
system.
Steps:
1. Enable cURL (see http://ca3.php.net/manual/en/ref.curl.php).
For windows: In order to enable this module on a Windows environment, you must copy
libeay32.dll and ssleay32.dll from the DLL folder of the PHP/Win32 binary
package to the SYSTEM folder of your Windows machine.
(Ex: C:\WINNT\SYSTEM32 or C:\WINDOWS\SYSTEM)
2. Uncomment the cURL extension in the php.ini file:
extension=php_curl.dll
Functionality:
1. Its a function and accepts three parameters (you can, of course, change this)
get_file1($file, $local_path, $newfilename)
$file : is the filename of the object to be retrieved
$local_path : is the local path to the directory to store the object
$newfilename : is the new file name on the local system
Mark Dhas wrote :1812
I don't believe this code actually uses the localpath
variable, so by default this file should save to the cwd
(current working directory).
To save the file to the directory of your choosing change
the following line