Php > Miscellaneous
Using cURL to download a file programmatically
Using cURL to download a file programmatically 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) 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 2. To use it: $wav_file = get_file1($filename, $local_path, $newfilename); ?> cURL returns true on success and false on failure. The function: function get_file1($file, $local_path, $newfilename) { $err_msg = ''; echo "
Attempting message download for $file
"; $out = fopen($newfilename, 'wb'); if ($out == FALSE){ print "File not opened
"; exit; } $ch = curl_init(); curl_setopt($ch, CURLOPT_FILE, $out); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_URL, $file); curl_exec($ch); echo "
Error is : ".curl_error ( $ch); curl_close($ch); //fclose($handle); }//end function ?>
Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage