Last active
October 5, 2018 11:16
-
-
Save mehrshaddarzi/72c5ac62c909f5ca25ec53331ca042ee to your computer and use it in GitHub Desktop.
download file with Curl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Curl With Getting Header | |
$curl = curl_init(); | |
curl_setopt_array($curl, array( | |
CURLOPT_RETURNTRANSFER => 1, | |
CURLOPT_VERBOSE => 1, | |
CURLOPT_HEADER => array( | |
"cache-control: no-cache", | |
"content-type: application/x-www-form-urlencoded" | |
), | |
CURLOPT_TIMEOUT => 120, | |
CURLOPT_URL => 'https://api.hesabfa.com/v1/contact/getcontacts', | |
CURLOPT_POST => 1, | |
CURLOPT_POSTFIELDS => HESABFA_API_PARAM | |
)); | |
$response = curl_exec($curl); | |
$err = curl_error($curl); | |
curl_close($curl); | |
// Then, after your curl_exec call: | |
list($header, $body) = explode("\r\n\r\n", $response, 2); | |
$result = json_decode($body, true); | |
//echo $response; | |
echo '<pre>'; | |
print_r($result); | |
$ch = curl_init(); | |
/** | |
* Set the URL of the page or file to download. | |
//curl_setopt($request, CURLOPT_TIMEOUT, 300); //set timeout to 5 mins | |
//curl_setopt($request, CURLOPT_RETURNTRANSFER, true); | |
*/ | |
curl_setopt($ch, CURLOPT_URL,'http://lril2.maralhost.com/~ayandero/brand/md.zip'); | |
$fp = fopen('rss.zip', 'w+'); | |
/** | |
* Ask cURL to write the contents to a file | |
*/ | |
curl_setopt($ch, CURLOPT_FILE, $fp); | |
curl_exec ($ch); | |
curl_close ($ch); | |
fclose($fp); | |
//from ftp | |
$SERVER_ADDRESS=""; | |
$SERVER_USERNAME=""; | |
$SERVER_PASSWORD=""; | |
$conn_id = ftp_connect($SERVER_ADDRESS); | |
// login with username and password | |
$login_result = ftp_login($conn_id, $SERVER_USERNAME, $SERVER_PASSWORD); | |
$server_file="test.pdf" //FTP server file path | |
$local_file = "new.pdf"; //Local server file path | |
##----- DOWNLOAD $SERVER_FILE AND SAVE TO $LOCAL_FILE--------## | |
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) { | |
echo "Successfully written to $local_file\n"; | |
} else { | |
echo "There was a problem\n"; | |
} | |
ftp_close($conn_id); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment