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.

Recommended Answers

All 7 Replies

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

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

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.

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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.