Hi all, I am not too good at PHP but i am learning. I have a site that is mostly PHP script, one page is to call a file and dump it into MySQL. Problem is the webhost wont allow fopen command, so i am trying to get the script to look in the same directory it resides to get the file and dump to mysql
Here is the piece of code that needs changing
Code:
$f = fopen("http://domain.here/thisfile.txt", "r");
if (!$f)
die("Cannot download thisfile.txt!");
mysql_query("DELETE FROM bans WHERE comment LIKE 'PeerGuardian: %'") or sqlerr(__FILE__, __LINE__);
i need the script to pull "thisfile.txt" from the wwwroot, (this script actually sits in the wwwroot)
the complete file is this
Code:
<?
// This script downloads/adds/updates peerguardian IP ranges in the bans table.
require_once("backend/functions.php");
dbconn();
if (get_user_class() < UC_ADMINISTRATOR)
die;
$f = fopen("http://domain.here/thisfile.txt", "r");
if (!$f)
die("Cannot download thisfile.txt!");
mysql_query("DELETE FROM bans WHERE comment LIKE 'PeerGuardian: %'") or sqlerr(__FILE__, __LINE__);
$n = 0;
$o = 0;
$dt = sqlesc(get_date_time());
while (!feof($f))
{
++$o;
$s = rtrim(fgets($f));
$i = strrpos($s, ":");
if (!$i) continue;
$comment = sqlesc("PeerGuardian: " . substr($s, 0, $i));
$s = substr($s, $i + 1);
$i = strpos($s, "-");
$first = ip2long(substr($s, 0, $i));
$last = ip2long(substr($s, $i + 1));
if ($first == -1 || $last == -1) continue;
mysql_query("INSERT INTO bans (added, addedby, first, last, comment) VALUES($dt, $uid, $first, $last, $comment)") or sqlesc(__FILE__, __LINE__);
++$n;
}
$o -= $n;
print("$n ranges imported, $o line(s) was discarded.");
?>
Any help to do this and point me in the right direction is most appreciated, and my sincere thanks to those who take the time to look at this for me.