Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

PHP Warning: Fopen

SpaceshipSpaceship
NamecheapNamecheap
SpaceshipSpaceship
Watch

baris22

Established Member
Impact
1
Hello all,

I get an error saying

[29-Sep-2007 20:45:58] PHP Warning: fopen(AS/<br /&gt [<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
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
The file it's trying to open is wrong, "AS/<br /&gt" doesn't exist.
 
0
Close
Probably $userinfo is not in the right format. Try to add a few "echo" to see what the variables contain.
 
0
Close
I am probably way off, but if you at php.ini to make sure f open is is set for no or yes.
just a thought I had problems with that when I was ahving an f open problem, that fixed it, but my code was ok, so anywho,
good luck
 
0
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back