tags:

views:

71

answers:

1

Please bear with me, I'm trying to learn php and all about how deal with files & setup on the server side. All was fine until I recently had to switch my hosting site. This new hosting site has their url_fopen turned off.

My previous script was using:

file_get_contents ("that.htm");

but now I need to use cURL. I've figured out how to load a remote file without any problems. I then save it (still using file_put_contents since it's not restricted) and re-access this cached file as follows:

$path = $_SERVER["PHP_SELF"];
$file = replace("this.php","that.htm",$path);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $file);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_HEADER, 0);

$data = curl_exec($ch);
curl_close($ch);

*note: "this.php" is the file conatining the above script and "that.htm" is the cached file in the same directory (it doesn't have all the html inside of it like <html> or <body>, but it does have a <table>, if that makes a difference). Also, the file permissions of "that.htm" are set to 777.

My problem is I don't get any output from the $data (and I can see the "that.htm" has the appropriate contents as I can load the file directly in the browser).

So I get no output setting the $file:

I tried to add a var_dump after the $data but apparently the script never gets to that point.

I'm sure it's something silly, but in my searching of the net and this site I can't figure it out (all the examples just say "http://example.com").

+1  A: 

It looks like you want to access a (static) file in the same directory as the initial script file. In that case no http request is required.
What does the script print when you increase the error reporting level like this?

error_reporting(E_ALL);
ini_set('display_errors', 1);

file_get_contents ("./that.htm");

Any error/warning messages?

VolkerK
LOL that works perfectly! Ok so why does that work when the url_fopen is off?... can they make php any more convoluted?
fudgey
f_g_c('./that.htm') is handled by the file:-"wrapper" (i.e. the local file system). And url_fopen has no effect on that "wrapper", only on "http:", "ftp:" and so on.
VolkerK