Return to Snippet

Revision: 10734
at January 11, 2009 20:00 by jimmysessions

Initial Code
* Copy File from HTTPS/SSL location
* @param string $FromLocation
* @param string $ToLocation
* @return boolean
function copySecureFile($FromLocation,$ToLocation,$VerifyPeer=false,$VerifyHost=true)
// Initialize CURL with providing full https URL of the file location
$Channel = curl_init($FromLocation);
// Open file handle at the location you want to copy the file: destination path at local drive
$File = fopen ($ToLocation, "w");
// Set CURL options
curl_setopt($Channel, CURLOPT_FILE, $File);
// We are not sending any headers
curl_setopt($Channel, CURLOPT_HEADER, 0);
// Disable PEER SSL Verification: If you are not running with SSL or if you don't have valid SSL
curl_setopt($Channel, CURLOPT_SSL_VERIFYPEER, $VerifyPeer);
// Disable HOST (the site you are sending request to) SSL Verification,
// if Host can have certificate which is nvalid / expired / not signed by authorized CA.
curl_setopt($Channel, CURLOPT_SSL_VERIFYHOST, $VerifyHost);
// Execute CURL command
// Close the CURL channel
// Close file handle
// return true if file download is successfull
return file_exists($ToLocation);
echo file_get_contents("");exit;
// Function Usage
echo 'File transferred successfully.';
echo 'File transfer failed.';

Initial URL

Initial Description

Initial Title
Downloading a File from Secure website (https) using CURL

Initial Tags
curl, php

Initial Language