[PHP] Remote bestand uitlezen lukt niet

Pagina: 1
Acties:

  • djc
  • Registratie: December 2001
  • Laatst online: 08-09-2025
Op een van mijn hosting servers lukt het niet om bestanden van andere servers met behulp van file("http://www.blahblah.nl/") te lezen. Er draait PHP 4.1.2 (phpinfo()) met allow_url_fopen op On, en het script (source) draait wel op mijn localhost en op de server van de VU. Waarom lukt het dan niet op mijn eigen host?

Rustacean


Verwijderd

Volgens mij gaat allow_url_fopen over fopen() en niet over file().
Probeer us fopen() inplaats van file().

  • SWINX
  • Registratie: Juni 2001
  • Laatst online: 02-06 23:18
werkt dit?

PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?
$fp = fopen ("http://www.nrc.nl/fs/index.html","r");

if(!$fp)
{ 
  echo("Error: Can't open file"); 
}

else
{ 
  while($line = fgets($fp, 128))
  {
    
    if (substr_count($line, '<img src="/images/'))
    {
      $output = $line;
    }
  }
}

$output = str_replace('olor="#000000" width="404"><tr><td><img src="','<img src="http://www.nrc.nl', $output);
$output = str_replace(' border="0" alt=""></td></tr><','>',$output);

echo $output;

?>

Mannen komen van Mars Tweakers, vrouwen van Venus Bokt


  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06-2025

drm

f0pc0dert

PHP.net/file
Tip: You can use a URL as a filename with this function if the "fopen wrappers" have been enabled. See fopen() for more details.
PHP.net/fopen
fopen ( $filename, ... )
(...)
If filename begins with "http://" (not case sensitive), an HTTP 1.0 connection is opened to the specified server, the page is requested using the HTTP GET method, and a file pointer is returned to the beginning of the body of the response. A 'Host:' header is sent with the request in order to handle name-based virtual hosts.
PHP.net/configuration/General Configuration Directives
allow_url_fopen boolean
  • This option enables the URL-aware fopen wrappers that enable accessing URL object like files. Default wrappers are provided for the access of [url=http://www.php.net/manual/en/features.remote-files.php]remote files[/url] using the ftp or http protocol, some extensions like zlib may register additional wrappers.
De manual lezen, en een beetje klikken is zooo lastig :z ;)

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


  • djc
  • Registratie: December 2001
  • Laatst online: 08-09-2025
@ drm: dat had ik ook allemaal wel gelezen, alleen dacht ik dat On ook goed was voor allow_url_fopen. Kennelijk mag dat alleen 1 zijn. Eens kijken of dat wel werkt.

Rustacean


  • djc
  • Registratie: December 2001
  • Laatst online: 08-09-2025
Geeft ie die can't open foutmelding.

Als ik ini_set() gebruik schijnt PHP er helemaal mee te kappen, dus ik moet wachten tot mijn host allow_url_fopen op 1 zet ipv On.

Rustacean


  • Lethalis
  • Registratie: April 2002
  • Niet online
Vreemd, volgens mij moet het toch echt gewoon 'On' zijn in plaats van 1 :?

Ask yourself if you are happy and then you cease to be.

Pagina: 1