Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php] zapisywanie tresci obrazka, do pliku jpg
lucas131
post
Post #1





Grupa: Zarejestrowani
Postów: 30
Pomógł: 0
Dołączył: 21.03.2005

Ostrzeżenie: (0%)
-----


Dzięki socketów pobrałem treść obrazka, jest to juz sukces gdyz przez link nie da sie go sciagnac.
Pobieam tresc w nastepujacy sposob:
Kod
$fp = fsockopen("www.lightspeedgalleries.com", 80, $errno, $errstr, 30);
if (!$fp) {
   echo "$errstr ($errno)<br />\n";
} else {
   $out = "GET /fg/jor/001/images/55.jpg HTTP/1.1\r\n";
   $out .= "Host: www.lightspeedgalleries.com\r\n";
   $out .=  "Referer: http://www.lightspeedgalleries.com/fg/jor/001/index.php?r=lucas131-rev&nc=1\r\n";
   $out .= "Connection: Close\r\n\r\n";

   fwrite($fp, $out);
   while (!feof($fp)) {
   $s =  fgets($fp);
   if(strstr($s, "\n"))
   {
     echo "<br>".$s;
     if(strstr($s, "Content-Length:"))
     {
       $rozmiar=explode("Content-Length: ", $s);
       $dlugosc=$rozmiar[1];
     }    
   }  
   ++$pp;
   if ($pp=='9')
   {
     $dane_obrazka=fread($fp, $dlugosc);
     break;
   }
   }
  
   fclose($fp);
}


Po 9 linijce zazyna sie tresc obrazka zapisuje ja do $dane_obrazka, nastepnie zapisuje:
Kod
$obrazek=$dane_obrazka;
$plik = fopen($nazwaPliku, 'wb');
fwrite($plik, $obrazek, $dlugosc);
fclose($plik);



Wynik wyswietlany w przegladarce:
HTTP/1.1 200 OK
Date: Mon, 28 Mar 2005 12:06:49 GMT
Server: Apache/1.3.26 (Unix) php/4.1.2
Last-Modified: Sat, 05 Feb 2005 00:58:16 GMT
ETag: "298195-19f3-42041a28"
Accept-Ranges: bytes
Content-Length: 6643
Connection: close
Content-Type: image/jpeg

˙Ř˙Ű ˙Ŕ (tresc obrazka)

Zapisnay plik ma ,48kb, zgadza sie tylko podglad jest niedostepny... Dlaczego?
Go to the top of the page
+Quote Post
SongoQ
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 2 923
Pomógł: 9
Dołączył: 25.10.2004
Skąd: Rzeszów - studia / Warszawa - praca

Ostrzeżenie: (0%)
-----


Wisisz mi juz piwo (hehe)

  1. <?php
  2.  
  3. $fp = fsockopen(&#092;"www.lightspeedgalleries.com\", 80, $errno, $errstr, 30);
  4. if(!$fp)
  5. {
  6. echo &#092;"$errstr ($errno)<br />n\";
  7. }
  8. else
  9. {
  10. $out = &#092;"GET /fg/jor/001/images/12.jpg HTTP/1.1rn\";
  11. $out .= &#092;"Host: www.lightspeedgalleries.comrn\";
  12. $out .= &#092;"Referer: http://www.lightspeedgalleries.com/fg/jor/001/index.php?r=lucas131-rev&nc=1rn\";
  13. $out .= &#092;"Connection: Closernrn\";
  14.  
  15. fwrite($fp, $out);
  16. while(!feof($fp))
  17.  $s .= fgets($fp);
  18. fclose($fp);
  19.  
  20. $aNaglowki = explode(&#092;"n\", $s);
  21.  
  22. for($i = 0; $i < 10; $i++)
  23. $szNaglowki .= $aNaglowki[$i].&#092;"n\";
  24.  
  25. $szObrazek = str_replace($szNaglowki, '', $s);
  26.  
  27. }
  28.  
  29. $rPlik = fopen('a.jpg', 'wb');
  30. fwrite($rPlik, $szObrazek);
  31. fclose($rPlik);
  32. ?>


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 11:34