Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $url = parse_url('https://site/file.jpg');
- $host = $url['host'];
- $port = $url['port'];
- $path = $url['path'];
- $query = $url['query'];
- if(!$port)$port = 80 ;//tcp
- $request = "GET $path HTTP/1.1\r\n"
- ."Host: $host\r\n"
- ."User-Agent: Mozilla/5.0\r\n"
- ."Connection: close\r\n"
- ."\r\n";
- /////////////
- $fp = ($url['scheme']=='https' )?
- fsockopen("ssl://{$host}", 443, $errno, $errstr, 30):
- fsockopen("tcp://{$host}", 80, $errno, $errstr, 30);
- $imgName=tempnam(sys_get_temp_dir(),'img');
- $hnd = fopen($imgName, 'w');
- ob_start(function($buffer) use($hnd){fwrite($hnd, $buffer);}, 1);
- $type=false;
- $bStart=true;
- if ( $fp ) {
- if ( fwrite($fp, $request) ) {
- while ( !feof($fp) ) {
- $out=fread($fp, 1024);
- if($bStart){
- echo $h=substr($out, strpos($out, "\r\n\r\n") + 4);
- $type=exif_imagetype($imgName);
- if($type==false)break;
- $bStart=false;
- }else{
- echo $out;
- }
- }
- }
- fclose($fp);
- }
- ob_end_clean();
- fclose($hnd);
- echo ($type);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement