Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $url = $_GET['url'];
- if ( $url && preg_match('#^(http|https)//:#i', $url) ) {
- $ch = curl_init();
- curl_setopt_array($ch, array(
- CURLOPT_URL => $url,
- CURLOPT_HEADER => 1,
- CURLOPT_NOBODY => 1,
- CURLOPT_RETURNTRANSFER => 1 ,
- CURLOPT_TIMEOUT, 5
- ));
- $response = curl_exec($ch);
- $lines = explode("\r\n", $response);
- $headers = array();
- foreach ($lines as $line) {
- $temp = explode(': ', $line);
- $headers[strtolower($temp[0]) ] = $temp[1];
- }
- if ( isset($headers['content-type']) && isset($headers['content-length']) && $headers['accept-ranges'] == 'bytes' ) {
- if ( !preg_match('#^image/(png|jpeg)$#', $headers['content-type']) ) {
- die('ERROR:INVALID_TYPE');
- }
- else if ( $headers['content-length'] < 20000 ) {
- die('ERROR:TOO_SMALL');
- }
- else if ( $headers['content-length'] > 1000000 ) {
- die('ERROR:TOO_BIG');
- }
- if ( ( $data = file_get_contents($url) ) !== false ) {
- die( 'data:' + $headers['content-type'] . ';base64,' . base64_encode($data) );
- }
- }
- }
- echo('ERROR');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment