PHP: How Download Images using fsockopen?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • qxxx
    Confirmed User
    • Dec 2002
    • 92

    #1

    PHP: How Download Images using fsockopen?

    I am working on this shit the wohle 2 days!! damn. I am trying to download a thumbnail with php to my server. I could do this with the php "file" function. But some fucking webmasters have this referer protection for the images. If the referer is Nothing or wrong then I cant download the thumbnail file just some redirected html crap.

    I can set the referer using fsockopen, can anyone show me how to download an image using fsockopen?


    thanks,
    Statistically, 5 out of 6 people enjoy Russian Roulette.
  • SMG
    Confirmed User
    • Aug 2003
    • 1798

    #2
    Here, this is a function I wrote in php a couple years ago that I used to get by that kind of thing for some other spidering. I modified it a little to make it work a little better for what u want, but havent tested it ... should work though

    usage:
    $file_array = fakefile('www.blah.com','/path/to/file.ext','http://www.blah.com');

    function fakefile($host, $file,$referer = '') {
    //this function does the same thing as file(), but makes its user-agent a standard browser and lets referer be controlled
    $filecon = fsockopen($host, 80);
    set_socket_blocking($filecon, false);
    $i = 0;
    $return_array = array();
    $str = "";
    $str2 = "";
    $p = "GET $file HTTP/1.1\r\n";
    $p .= "Host: $host\r\n";
    $p.= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; COM+ 1.0.2204)\r\n";
    $p .= "Http-referer: $referer\r\n";
    $p.= "\r\n";

    fputs ($filecon,$p);
    while ($str=fgets($filecon,2000)) {
    $return_array[$i] = $str;
    print $str;
    $i++;

    }
    fclose($filecon);
    return $return_array;

    }
    TGP Webmasters: sign up for the top 100 tgp list!
    Submit galleries
    If you add me to icq (title) make sure to mention GFY or I'll think you're a bot and deny you.

    Comment

    • qxxx
      Confirmed User
      • Dec 2002
      • 92

      #3
      thanks! but... is not working well, here is a sample:

      PHP Code:
      $file_array = fakefile("pibfree.com","/sites/d/david/hardcore-
      vip/gal1/thumbnails/tn_hardcore-fuck-
      03.jpg","http://pibfree.com/sites/d/david/hardcore-vip/gal1/");
      
      //echo ("EE: $file_array[1]");
      $s = implode ("", $file_array);
      echo $s; 
      
      The Script will receive not the whole data, only about 900 bytes. But the Picture is 2KB or so.
      you can test it if you want, maybe you find the error?
      I am trying to get Thumbnail #3 from http://pibfree.com/sites/d/david/har...-babes-132.htm

      The function set_socket_blocking is not working for me, i get only empty data if i use it ( set_socket_blocking($filecon, false); )
      Statistically, 5 out of 6 people enjoy Russian Roulette.

      Comment

      • qxxx
        Confirmed User
        • Dec 2002
        • 92

        #4
        It works!

        i combined few scripts i found on the Inet together and now it works... here is the working result, work of 2 days.., maybe someone can use it (ir me again):

        You need 2 files:

        File 1: browseremulator.class.php
        Download it here:
        http://www.bitfolge.de/index.php?l=de&s=befopen

        File 2: (the Example file in the zip is not working for me if i want download binary files like pics) here is the working version:

        PHP Code:
        <? 
        
        require ("browseremulator.class.php");
        
        $be = new BrowserEmulator(); 
        $be->addHeaderLine("Referer", "http://pibfree.com/sites/d/david/ebony/gal5/"); 
        $be->addHeaderLine("Accept-Encoding", "x-compress; x-zip"); 
        
        $file = $be->fopen("http://pibfree.com/sites/d/david/hardcore-vip/gal1/thumbnails/tn_hardcore-fuck-03.jpg"); 
        $response = $be->getLastResponseHeaders(); 
         
        while ($line = fread($file, 1024)) { 
                $buffer .= $line;
            }
        
            preg_match('/Content-Length: ([0-9]+)/', $buffer, $parts);
            $dt = substr($buffer, - $parts[1]);
        
        // This will write the downloaded file to ttt.jpg:
        fclose($file); 
        $remote = fopen("./ttt.jpg", 'wb');
        fwrite($remote,$dt);
        fclose($remote);
        ?>


        .... i am working on my own Preview Gallery Post (dont know the right name) like madthumbs.com ... but the submitter has not to upload any pic, my script will do this automatically.

        q.
        Statistically, 5 out of 6 people enjoy Russian Roulette.

        Comment

        Working...