Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Function to download a file (needed in one of the programming missions)
- function htsGetFile($url, $filename) {
- $cookiefile = "cookie.txt";
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0');
- curl_setopt($ch, CURLOPT_AUTOREFERER, true);
- curl_setopt($ch, CURLOPT_REFERER, $url);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile); // Cookiejar on creation, cookiefile on use
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // We need tot get the data back.
- curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //Will not check the ssl sertification.
- $rawdata = curl_exec($ch);
- if(file_exists($filename)){
- unlink($filename);
- }
- $fp = fopen($filename, 'wb');
- fwrite($fp, $rawdata);
- fclose($fp);
- if(curl_errno($ch)) {
- return false;
- } else {
- return $rawdata;
- }
- curl_close ($ch);
- }
- $username = "*******";
- $password = "*******";
- $url = "https://www.domain/path/";
- $file = "download.png";
- if (htsLogin($username, $password))
- if (htsGetHTML($url) !== false)
- if (htsGetFile($url, $file) !== false)
- $img = htsGetFile($url, $file);
- else
- echo 'Getting file went wrong.';
- else
- echo 'Getting page went wrong.';
- else
- echo 'Can't login.';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement