Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- set_time_limit(0); // убираем ограничение по времени выполнения скрипта
- function random_string($length){ // функция генерации рандомной строки
- $chars = "abcdefghijklmnopqrstuvwxyz1234567890"; // символы из которых генерируем
- $numChars = strlen($chars); // Определяем длину $chars
- $string = ''; // задаем пустую переменную
- for ($i = 0; $i < $length; $i++) { // Собираем строку
- $string .= substr($chars, rand(1, $numChars) - 1, 1);
- }
- return $string; // Возвращаем готовую строку
- }
- function curl_tt($url){
- $ch = curl_init();
- $userAgent = 'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0';
- curl_setopt( $ch, CURLOPT_USERAGENT, $userAgent );
- curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 3);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- $data = curl_exec($ch);
- curl_close($ch);
- return $data;
- }
- while (1) {
- $randstring = random_string(5); // генерируем рандомную сроку
- $htmldata = curl_tt('https://prnt.sc/1'.$randstring); // подставляем рандомную строку и получаем код страницы
- preg_match_all('/<meta name=\"twitter:image:src\" content=\"(.*?)\"\/>/is',$htmldata,$img_url); // парсим регуляркой url картинки
- if (strlen($img_url[1][0]) > 1) { // проверяем длину полученной строки, если больше 1 - картинка по этому адресу есть
- $localname = array_pop(explode('/',$img_url[1][0])); // разбиваем строку в массив и извлекаем последний элемент массива (т.е. imagename.png)
- $localpath = "./images/".$localname; // определяем куда будет сохраняться картинка локально. у меня заранее создана папка images
- file_put_contents($localpath, curl_tt($img_url[1][0])); // скачиваем, можно было бы реализовать через curl, но на мой взгляд это проще и быстрее
- echo "<span style='color: green; display: block; margin-bottom: 50px;'>Сохранение - ".$localname." , url - http://prntscr.com/1".$randstring." , скачиваем с ".$img_url[1][0]."</span>";
- } else {
- echo "<span style='color: red; display: block; margin-bottom: 50px;'>По адресу http://prntscr.com/1".$randstring." нет картинки</span>";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment