Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
change fopen to outside URL to local file
Old 04-18-2005, 02:52 AM **SOLVED** change fopen to outside URL to local file
Junior Talker

Posts: 1
Trades: 0
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.

Last edited by vientorio; 04-18-2005 at 04:05 AM.. Reason: **SOLVED**
vientorio is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to change fopen to outside URL to local file
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.49107 seconds with 12 queries