Created
July 12, 2016 04:00
-
-
Save softsolution/eaa4715f6fba6457348816776dad1365 to your computer and use it in GitHub Desktop.
скачивание файла посредством 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 | |
$url="http://neotext.ru/files/14/copyright_market/thumb/206397-1326458661.jpg"; | |
$file = '/download/test.dat'; | |
curl_download($url, $file); | |
/** | |
* Функция скачивания удаленного файла на сервер | |
* void curl_download(string $url, string $file) | |
* | |
* @param string url - путь к удаленному файлу | |
* @param string file - путь к локальному файлу (в него записываем файл) | |
* | |
* @return void | |
* | |
*/ | |
function curl_download($url, $file) | |
{ | |
// открываем файл, на сервере, на запись | |
$dest_file = @fopen($file, "w"); | |
// открываем cURL-сессию | |
$resource = curl_init(); | |
// устанавливаем опцию удаленного файла | |
curl_setopt($resource, CURLOPT_URL, $url); | |
// устанавливаем место на сервере, куда будет скопирован удаленной файл | |
curl_setopt($resource, CURLOPT_FILE, $dest_file); | |
// заголовки нам не нужны | |
curl_setopt($resource, CURLOPT_HEADER, 0); | |
// выполняем операцию | |
curl_exec($resource); | |
// закрываем cURL-сессию | |
curl_close($resource); | |
// закрываем файл | |
fclose($dest_file); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment