stuppid_bot

Untitled

Apr 19th, 2013
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.99 KB | None | 0 0
  1. <?php
  2.  
  3. $app = include 'app.php';
  4. $url = parse_url($_POST['url']);
  5. $error = '';
  6.  
  7. if ($url['scheme'] != 'http') {
  8.     $error = 'Ссылка должна начинаться с "http://"';
  9. }
  10. else if (!$url['path'] || $url['path'] == '/') {
  11.     $error = 'Не указан путь до файла';
  12. }
  13. else {
  14.     $fh = fsockopen($url['host'], $url['port'] ? $url['port'] : 80, $errno, $error, 1);
  15.    
  16.     if ($fh) {
  17.         fwrite($fh, "GET " . $url['path'] . ($url['query'] ? '?' . $url['query'] : '') . " HTTP/1.1\r\nHost: {$url['host']}\r\nConnection: close\r\n\r\n");
  18.         $status = explode(' ', fgets($fh), 3);
  19.  
  20.         if ($status[1] != 200) {
  21.             $error = $status[1] . ' ' . $status[2];
  22.         }
  23.         else {
  24.             $headers = array();
  25.  
  26.             while (1) {
  27.                $header = rtrim( fgets($fh) );
  28.  
  29.                // \r\n\r\n заголовки кончились
  30.                if ($header == '') {
  31.                    break;
  32.                }
  33.  
  34.                list($key, $val) = explode(': ', $header);
  35.                $headers[ strtolower($key) ] = $val;
  36.            }
  37.  
  38.            if ( !preg_match('#^image/(' . implode('|', $app['allowedImageTypes']) . ')$#', $headers['content-type']) ) {
  39.                $error = $app['someErrors']['invalidFileType'];
  40.            }
  41.            else if ( $headers['content-length'] < $app['minImageSize'] ) {
  42.                $error = $app['someErrors']['imageTooSmall'];
  43.            }
  44.            else if ( $headers['content-length'] > $app['maxImageSize'] ) {
  45.                $error = $app['someErrors']['imageTooBig'];;
  46.            }
  47.            else {
  48.                $data = '';
  49.                
  50.                while ( !feof($fh) ) {
  51.                    $data .= fread($fh, 8192);
  52.                }
  53.                
  54.                echo( 'data:' . $headers['content-type'] . ';base64,' . base64_encode($data) );
  55.            }
  56.         }
  57.        
  58.         fclose($fh);
  59.     }
  60. }
  61.  
  62. if ($error) {
  63.     echo("error:$error");
  64. }
  65.  
  66. ?>
Advertisement
Add Comment
Please, Sign In to add comment