<?php set_time_limit(0); // ob_implicit_flush(); 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 get_http_response_code($url) { // http $headers = get_headers($url); return substr($headers[0], 9, 3); } if (!file_exists('lightshot_images')) { // , mkdir('lightshot_images', 0777); } $options = array( 'http' => array( 'method' => "GET", 'header' => "Accept-language: en\r\n" . "User-Agent: Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10\r\n" ) ); $context = stream_context_create($options); while (1) { $randstring = random_string(5); // $htmldata = file_get_contents('https://prnt.sc/m' . $randstring, false, $context); // preg_match_all('/<meta name=\"twitter:image:src\" content=\"(.*?)\"\/>/is', $htmldata, $img_url); // url if (strlen($img_url[1][0]) > 1) { // , 1 - $imgs = str_replace('//st.prntscr', 'https://st.prntscr', $img_url[1][0]); $localname = array_pop(explode('/', $img_url[1][0])); // (.. imagename.png) $localpath = "./lightshot_images/" . $localname; // . if (get_http_response_code($imgs) != "200") { echo "<span style='color:red;display:block;margin-bottom:10px;font-size:14px;'>404. " . $imgs . " :(</span>"; } else { file_put_contents($localpath, file_get_contents($imgs, false, $context)); // , curl, echo "<span style='color:green;display:block;margin-bottom:10px;font-size:14px;'> - " . $localname . " , url - http://prntscr.com/m" . $randstring . " , " . $imgs . "</span>"; } } else { echo "<span style='color:red;display:block;margin-bottom:10px;font-size:14px;'> http://prntscr.com/m" . $randstring . " </span>"; } } ?>
Source: https://habr.com/ru/post/197228/
All Articles