Hello all,
I get an error saying
[29-Sep-2007 20:45:58] PHP Warning: fopen(AS/<br /> [<a href='function.fopen'>function.fopen</a>]: failed to open stream: No such file or directory in /home/x/public_html/x/article_online.php on line 39
Here is the lines from 36 to 43
Please help me
Here is the full code
Thank you very much
I get an error saying
[29-Sep-2007 20:45:58] PHP Warning: fopen(AS/<br /> [<a href='function.fopen'>function.fopen</a>]: failed to open stream: No such file or directory in /home/x/public_html/x/article_online.php on line 39
Here is the lines from 36 to 43
Code:
{
$myFile = "AS/".trim($ip);
$fp = fopen($myFile, "a");
if ($fp == "") return 0;
fwrite($fp, $msg."\r\n");
fclose($fp);
}
Please help me
Here is the full code
Code:
<?php
$dataFile = "article_submission.ip";
$sessionTime = 30;
function connect()
{
if (strstr($_SERVER['SERVER_ADDR'],"xxx") != "" || $_SERVER['SERVER_ADDR']=="xxx")
{
$db_host = "localhost"; // Host name
$db_user = "x"; // User name of your database
$db_password = "x"; // assword of your database
$db_name="x"; // Database name
$mysql_database = "x";
}
else
{
$db_host = "x"; // Host name
$db_user = "x"; // User name of your database
$db_password = "x"; // assword of your database
$db_name="x"; // Database name
$mysql_database = "x";
}
// To connect to database
mysql_pconnect($db_host,$db_user,$db_password);
mysql_select_db($db_name) or die("Can't select DB");
}
function SendMessageTo($ip, $msg)
{
$myFile = "AS/".trim($ip);
$fp = fopen($myFile, "a");
if ($fp == "") return 0;
fwrite($fp, $msg."\r\n");
fclose($fp);
}
function BroadCast($message)
{
global $dataFile;
$users = file($dataFile);
$currentTime = time();
for($i=0;$i<count($users);$i++)
{
$userInfo = explode("|", $users[$i]);
$fx = trim($userInfo[0]);
if ($fx != $_REQUEST['f'])
{
if ($currentTime - $userInfo[1] < 30)
SendMessageTo($userInfo[0], $message);
}
}
}
function GetID($clientFile)
{
global $dataFile;
$users = file($dataFile);
for($i=0;$i<count($users);$i++)
{
$userInfo = explode("|", $users[$i]);
$fl = trim($userInfo[0]);
if (!strcmp($fl, $clientFile)) return $i;
}
return -1;
}
function CreateID($dataFile)
{
global $dataFile;
$rec = sprintf("%-32.32s|%10.10s\r\n", $clientFile, "");
$recNo = filesize($dataFile) / 45;
$fl = fopen($dataFile, "a");
if ($fl != "")
{
fwrite($fl, $rec, 45);
fclose($fl);
return $recNo;
}
return -1;
}
function CleanUp()
{
global $dataFile;
$users = file($dataFile);
$currentTime = time();
for($i=0;$i<count($users);$i++)
{
$users[$i] = trim($users[$i]);
$userInfo = explode("|", $users[$i]);
if ($currentTime - $userInfo[1] >= 5)
{
$myFile = "AS/".trim($userInfo[0]);
if (file_exists($myFile)) unlink($myFile);
}
}
}
function SearchRecordsOnWebServer($list)
{
// $list[0] is the filename where results to be written
// $list[1] is the searchID to be send back
// $list[2] file type (Audio,Video...)
// $list[3] Search String
connect();
$sql_query = "select * from `filedetails` where type='".$list[2]."' and title like '%".$list[3]."%'";
$result = mysql_query($sql_query) or die(mysql_error());
if ($result != "")
{
$z = mysql_num_rows($result);
for ($i = 0 ; $i < $z ; $i++)
{
$rec = mysql_fetch_array($result);
//"A%d|%d|%s|%s|%d|%d|", list[0], remoteProcessID, type, temp->title, temp->description, temp->index, temp->owner);
$msg = "A".$list[1]."|".$list[2]."|".$rec['title']."|".$rec['description']."|".$rec['id']."|1_1_1_1_1_1_1_1"."|".$rec['quality'];
SendMessageTo($list[0], $msg);
}
}
}
function SendFile2Client($list)
{
// $list[0] is the searchID to be send back
// $list[1] is the filename where results to be written
connect();
$sql_query = "select * from `filedetails` where id='".$list[0]."'";
$result = mysql_query($sql_query) or die(mysql_error());
if ($result != "")
{
if (mysql_num_rows($result) > 0)
{
$rec = mysql_fetch_array($result);
//str.Format("F%d|%s|%s|%d|%s|", art.type, art.title, art.description, art.index, IPFileName);
$msg = "F".$rec['type']."|".$rec['title']."|".$rec['description']."|".$rec['id']."|1_1_1_1_1_1_1_1|".$rec['quality']."|".$rec['links'];
SendMessageTo($list[1], $msg);
}
}
}
function ProcessServerRecord($data)
{
connect();
$action = $data[0];
$data = substr($data, 1);
$list = explode("|", $data);
if ($action=="R")
{
// Get Record whose id = $list[0];
$sql_query = "select * from `filedetails` where id='".$list[0]."'";
$result = mysql_query($sql_query) or die(mysql_error());
if ($result != "" && mysql_num_rows($result) > 0)
{
$rec = mysql_fetch_array($result);
// Get Quality field
$quality = $rec['quality'];
for ( $i = 0 ; $i < 10 ; $i++)
{
if ($quality[$i]==0)
{
$quality[$i]=$list[1];
break;
}
}
// Update Record
$sql_query = "update `filedetails` set `quality`='".$quality."' where id='".$list[0]."'";
$result = mysql_query($sql_query) or die(mysql_error());
}
}
else if ($action=="S")
{
SendFile2Client($list);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
// If ip list file does not exist create it
if(!file_exists($dataFile)) fclose(fopen($dataFile, "w+"));
// Get Ip address of client
$ip = $_SERVER['REMOTE_ADDR'];
// If this is initialization clear clients message queue file,
// Send current available version and download urls to client for further processing
if ($_REQUEST['a']=="init")
{
$fileName = $_REQUEST['ip']."_".$ip;
$fileName = str_replace(".", "_",$fileName);
// if (file_exists($fileName)) unlink($fileName);
CleanUp();
$MYID = GetID($fileName);
if ($MYID==-1) $MYID = CreateID($fileName);
print $fileName."\r\n".$MYID."\r\nversion=1.0;http://www.x.com/h.exe;http://www.x.com/sh.exe";
exit();
}
else if ($_REQUEST['a']=="send")
{
$t = strpos($_REQUEST['s'], "|");
$send2 = substr($_REQUEST['s'], 0, $t);
$data = substr($_REQUEST['s'], $t+1);
if (strlen($send2) > 0)
{
if ($send2=="1_1_1_1_1_1_1_1")
ProcessServerRecord($data);
else SendMessageTo($send2, $data);
exit();
}
BroadCast($data);
// This is a search request and we need to search on web server also
if ($data[0]=="Q")
{
$data = substr($data, 1);
$list = explode("|", $data);
SearchRecordsOnWebServer($list);
}
}
else if ($_REQUEST['a']=="get")
{
$myFile = "AS/".$_REQUEST['f'];
if (!file_exists($myFile)) exit();
$list = file($myFile);
unlink($myFile);
for ($i=0;$i < count($list) ; $i++)
{
print $list[$i];
}
}
else if ($_REQUEST['a']=="online")
{
$rec = sprintf("%-32.32s|%10.10s\r\n", $_REQUEST['f'], time());
$fl = fopen($dataFile, "r+");
if ($fl != "")
{
$offset = $_REQUEST['id']*45;
fseek($fl, $offset, 0);
fwrite($fl, $rec, 45);
fclose($fl);
}
}
?>
Thank you very much






