Link to home
Start Free TrialLog in
Avatar of iam_david_lee
iam_david_lee

asked on

PHP fileopen

hi

i am trying to read an xml file, when i load a local file which is in the same directory it works fine... but when i try to load a xml file from another domain it gives me an error...


$xml_file = "http://www.somedomain.com/xml/atext.xml";

// Opens the file or gives an error message
$fp = fopen($xml_file, "r") or die("Could not open file");

// Reads the file or gives an error message
$data = fread($fp, filesize($xml_file)) or die("Could not read file");


i get the following error...

Warning: filesize(): Stat failed for http://www.somedomain.com/xml/atext.xml (errno=2 - No such file or directory) in /test.php on line 78

Warning: fread(): Length parameter must be greater than 0. in /test.php on line 78
Could not read file


can someone please help...


thanks
Avatar of star_trek
star_trek


try instead
$file_contents = file_get_contents($xml_file);
Avatar of iam_david_lee

ASKER

thanks for the reply... but still same error. i think its its something to do with this line, it doesnt like the filesize or something...

$data = fread($fp, filesize($xml_file)) or die("Could not read file");
ASKER CERTIFIED SOLUTION
Avatar of tdterry
tdterry
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I agree that the file_get_contents() will work, as previously stated.
Avatar of blue_hunter
when you using fopen(), try to check to make sure that allow_url_fopen is enabled. If it is switched off, PHP will emit a warning and the fopen call will fail.


i have the same comment as above see my comments above.