Ravan Vinod
Ravan Vinod

Reputation: 35

php file() method is not working in server

I am using HTTP API in my application. When I am calling that URL using file() method it is working fine in localhost but not in server.

I am using centos server.

In Command prompt :

#telnet www.example.com

it is getting resonse throw terminal but not in browser

Code :

<?php 
 $url = "http://www.example.com";
 $arr = file($url);
 echo '<pre>';
 print_r($arr);
 echo '</pre>';
?>

Upvotes: 0

Views: 173

Answers (2)

Sergey P. aka azure
Sergey P. aka azure

Reputation: 4742

From php.net documentation:

A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename.

And here is explanation about fopen wrappers: http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

Check your php.ini and find allow_url_fopen option. It should be enabled to use this functionality

Upvotes: 0

Lorenz Meyer
Lorenz Meyer

Reputation: 19915

You probably have allow_url_fopen disabled on the server. Enable it to get your code to work.

Upvotes: 1

Related Questions