Jump to content

can i use fopen?


a2bardeals

Recommended Posts

I am trying to create a PHP page with a variable's value being looked up from google's geocoding service.

Basically I have a MySQL database table with customer names and addresses. On the page I am working on I want to do a quick lookup to:

 

http://maps.google.com/maps/geo?q=Address+Info&key=abcdefg&output=csv

 

when you type this in a browser in returns a small line of text that has the lat/long seperated by commas.

 

How can I get that data from the HTTP request into a variable without leaving my site?

 

I know you can use cURL but I cannot install it on my system (no compiler) so I am looking for an alternative...

 

i was thinking i could use fopen() or fsockopen() but I have no idea how to set this up.

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/42581-can-i-use-fopen/
Share on other sites

returns nothing...am i calling the function right?

 


<?

function file_get_contents2($filename) {
     $fd = fopen("$filename", "rb");
     $content = fread($fd, filesize($filename));
     fclose($fd);
     return $content;
} 

$string = file_get_contents2('http://maps.google.com/maps/geo?key=ABQIAAAAR0Cth1uWGX8aUnZOUNxxDRSTa-vPv41zs_3mMYBEENmT6-JqMxQvgmczA_f8sbJvBlQCW7hrjqwVQA&output=cvs&q=3060+Packard+Rd,+Ann+Arbor,+MI');

echo $string;
?>

Link to comment
https://forums.phpfreaks.com/topic/42581-can-i-use-fopen/#findComment-207352
Share on other sites

Looks right to me, maybe a half-assed solution is trying to include the file? I am not sure if it will work but give it a try

 

 

ob_start();
include("http://maps.google.com/maps/geo?key=ABQIAAAAR0Cth1uWGX8aUnZOUNxxDRSTa-vPv41zs_3mMYBEENmT6-JqMxQvgmczA_f8sbJvBlQCW7hrjqwVQA&output=cvs&q=3060+Packard+Rd,+Ann+Arbor,+MI");
$string = ob_get_contents();
ob_end_clean();

echo $string;

 

--FrosT

Link to comment
https://forums.phpfreaks.com/topic/42581-can-i-use-fopen/#findComment-207363
Share on other sites

as posted on: http://us2.php.net/manual/en/function.include.php

 

Warning

Windows versions of PHP prior to PHP 4.3.0 do not support accessing remote files via this function, even if allow_url_fopen is enabled.

 

allow_url_fopen that is probably disabled via your host, if that is there is really no luck for you unless you can google a allow_url_fopen workaround and find that.

 

--FrosT

Link to comment
https://forums.phpfreaks.com/topic/42581-can-i-use-fopen/#findComment-207373
Share on other sites

That would explain why the include didn't work and why file_get_contents didn't work

 

http://us2.php.net/manual/en/function.file-get-contents.php  (note version information)

 

The file_get_contents2(); would have worked if the fopen works. If the fopen is not allowed to connect to a remote site than I think you are SOL.

 

http://us2.php.net/manual/en/function.fopen.php

 

Maybe look through that at the user comments.

 

Best of luck.

 

--FrosT

 

 

Link to comment
https://forums.phpfreaks.com/topic/42581-can-i-use-fopen/#findComment-207390
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.