Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php]Jak sprawdzic czy plik istnieje
cholew
post
Post #1





Grupa: Zarejestrowani
Postów: 64
Pomógł: 0
Dołączył: 5.01.2007

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


Siema, tak jak w temacie, w jaki sposób można sprawdzić czy plik istnieje. Chodzi mi tu o plik na innym serwerze, np. jakis obrazek. (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
babejsza
post
Post #2





Grupa: Zarejestrowani
Postów: 407
Pomógł: 1
Dołączył: 4.03.2003
Skąd: warszawa

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


  1. <?php
  2. function url_validate( $link )
  3. {
  4. $url_parts = @parse_url( $link );
  5.  
  6. if ( empty( $url_parts["host"] ) ) return( false );
  7.  
  8. if ( !empty( $url_parts["path"] ) )
  9. {
  10. $documentpath = $url_parts["path"];
  11. }
  12. else
  13. {
  14. $documentpath = "/";
  15. }
  16.  
  17. if ( !empty( $url_parts["query"] ) )
  18. {
  19. $documentpath .= "?" . $url_parts["query"];
  20. }
  21.  
  22. $host = $url_parts["host"];
  23. $port = $url_parts["port"];
  24.  
  25. if (empty( $port ) ) $port = "80";
  26. $socket = @fsockopen( $host, $port, $errno, $errstr, 30 );
  27. if (!$socket)
  28. {
  29. return(false);
  30. }
  31. else
  32. {
  33. fwrite ($socket, "HEAD ".$documentpath." HTTP/1.0rnHost: $hostrnrn");
  34. $http_response = fgets( $socket, 22 );
  35.  
  36. if ( ereg("200 OK", $http_response, $regs ) )
  37. {
  38. return(true);
  39. fclose( $socket );
  40. } else
  41. {
  42.  
  43. return(false);
  44. }
  45. }
  46. }
  47.  
  48.  
  49. for($i=1500; $i<1610; $i++)
  50. {
  51. if(url_validate('http://www.arcademark.com/img/'.$i.'.png', 'r')) echo 'ok<br/>';
  52. else echo 'brak pliku<br>';
  53. }
  54. ?>
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: 25.12.2025 - 16:23