Created
July 6, 2017 12:03
-
-
Save vovadocent/d7b6d7fc06fea96d9cff68472ae6c1d3 to your computer and use it in GitHub Desktop.
Fast file download from remote url, using CURL
This file contains hidden or 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 | |
//$imurl - віддалений url файла | |
//$picpath - path до локального файла з новим іменем | |
function save_image($imurl, $picpath) { | |
$ch = curl_init(); | |
$fp = fopen($picpath, 'w'); | |
$ch = curl_init($imurl); | |
curl_setopt($ch, CURLOPT_TIMEOUT, 50); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); | |
curl_setopt($ch, CURLOPT_FILE, $fp); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); | |
curl_setopt($ch, CURLOPT_ENCODING, ""); | |
$res = curl_exec($ch); | |
curl_close($ch); | |
fclose($fp); | |
if (!$res || filesize($picpath) <= 1024) { | |
unlink($picpath); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment