[PHP] Curl Download File

// Url file cần tải
$fileUrl = 'http://example.com/logo.png';
// Đường dẫn file sau khi tải
$saveTo = 'logo.png';

$userAgent = $_SERVER['HTTP_USER_AGENT'];
$fp = fopen($saveTo, "w+");

if ($fp === false) {
    echo 'Lỗi';
}

$ch = curl_init($fileUrl);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_exec($ch);

if (curl_errno($ch)) {
    echo 'Lỗi';
}

$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
fclose($fp);

if ($statusCode == 200) {
    echo 'Đã tải';
} else {
    echo 'Lỗi';
}