0

Hello, I'm trying to read a text file which is on the web and then insert its contents in a database using PHP. I think my code is okay but I keep getting this error message which I think might be permission problems so I just need clarity on this. Here's my code.

$mysqlserver = "localhost";
$mysqllogin = "root";
$mysqlpassword = "";
$mysqldb = "ports";

$conn = mysql_connect("$mysqlserver", "$mysqllogin", "$mysqlpassword");

if (!$conn)
{
die('Could Not Connect To The MySQL Database<hr />' . mysql_error());
}

mysql_select_db("$mysqldb", $conn);

$url = 'http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.txt';
$feed = fopen($url, "r")
or die("Could Not Open The TEXT File<hr /> " . mysql_error());

$file = file_get_contents($url,true);


and here is the error I keep getting.


Warning: fopen(http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.txt) [function.fopen]: failed to open stream: No connection could be made because the target machine actively refused it. in C:\xampp\htdocs\csv.php on line 7
Could Not Open The TEXT File


and line 7 is this code

$feed = fopen($url, "r")

thanks in advance your help will be highly appreciated.

3
Contributors
7
Replies
9
Views
6 Years
Discussion Span
Last Post by kgizo
0

okay cwarn23 I'll try it out and let you know what happens. Thanks alot!!!

0

sorry man it still doesn't work I'm sure it has something to do with the firewall settings, but then again thank you.

0

I just tried my script on my localhost xampp and echo'ed $feed and after about 25 seconds of waiting for the page to download it eventually displayed all of the contents. So perhaps it is your firewall.

0

So that just confirms it, so thank you man I really appreciate it.

0

Have you try using include('service-names-port-numbers.txt')?
or using an iframe to open it such as <iframe src="<?php echo $url; ?>"/>?

0

thanks lps!!! I'll try it out and let you know.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.