Parsing Files in PHP
Let's consider the general principle of downloading
files during parsing. This is done using the
function file_get_contents
,
which is passed a parameter of some
URL pointing to the file
we want to download:
<?php
$data = file_get_contents('http://file-url');
?>
Then, using the function file_put_contents
we can save the downloaded data
into a file:
<?php
file_put_contents('file-name', $data);
?>
However, there is a nuance. The function file_get_contents
,
depending on the settings, may open URLs,
or it may not. To do this, we need to check
what value the PHP setting
'allow_url_fopen'
is set to. Let's do this
using the function ini_get
:
<?php
$val = ini_get('allow_url_fopen', true);
var_dump($val); // должно быть true или 1
?>
In case the setting is not enabled,
we can enable it using the function
ini_set
:
<?php
ini_set('allow_url_fopen', true);
?>
Check your 'allow_url_fopen'
setting.
If it is disabled, enable it.