Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] Kopiowanie zdjęć zzewnętrzego serwera
sweter
post
Post #1





Grupa: Zarejestrowani
Postów: 623
Pomógł: 11
Dołączył: 1.01.2009
Skąd: Wrocław

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


Witam,
chcę skopiować zdjęcie z Fotka.pl więc wykonuję takie polecenie:
  1. copy('http://c10.asteroid.pl/a.eu.fotka.pl.s3.amazonaws.com/057/738/57738379_640.jpg', '/images/plik.jpg');

Niestety, nie wiem czemu ale za każdym razem wyświetla mi:
Cytat
Warning: copy(/images/plik.jpg): failed to open stream: No such file or directory

Wszystkie ścieżki są oczywiście poprawne.
Może to jakieś zabezpieczenie ze strony serwera, aby nikt nie pobierał zdjęć?

Pozdrawiam
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Spirit86
post
Post #2





Grupa: Zarejestrowani
Postów: 607
Pomógł: 23
Dołączył: 8.09.2004
Skąd: Wrocław

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


If you have PHP5 and the HTTP stream wrapper enabled on your server, it's incredibly simple to copy it to a local file:
copy('http://somedomain.com/file.jpeg', '/tmp/file.jpeg');

Remote files. This needs allow_url_fopen to be enabled in php.ini, but it's the easiest method.

Alternatively you could use cURL if your PHP installation supports it. There's even an example.

And if you really want to do it manually use the HTTP module.

Don't even try to use sockets directly.

  1. $url = "http://other-site/image.png";
  2. $dir = "/my/local/dir/";
  3.  
  4. $rfile = fopen($url, "r");
  5. $lfile = fopen($dir . basename($url), "w");
  6.  
  7. while(!feof($url)) fwrite($lfile, fread($rfile, 1), 1);
  8.  
  9. fclose($rfile);
  10. fclose($lfile);



  1. $url = "http://other-site/image.png";
  2. $dir = "/my/local/dir/";
  3. $lfile = fopen($dir . basename($url), "w");
  4.  
  5. $ch = curl_init();
  6. curl_setopt($ch, CURLOPT_URL, $url);
  7. curl_setopt($ch, CURLOPT_HEADER, 0);
  8. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  9. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)');
  10. curl_setopt($ch, CURLOPT_FILE, $lfile);
  11.  
  12. fclose($lfile);
  13. curl_close($ch);
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 10.10.2025 - 11:07