...

View Full Version : Unable to write data into a file in my server using php



rick001
11-15-2011, 01:14 PM
Hey guys i am writing a code which will get data frm the user and then write a file in my server and well sadly i am really confused with the annoying errors and warnings i am getting plz help here is my code

<?php
//This File Gets the data from the chat setup form and then writes the chat file or edits it

//Get Data from the form
$cname=$_POST['cname'];
$nicklen=$_POST['nicklen'];
$msglen=$_POST['msglen'];
$pm=$_POST['pm'];
$msgh=$_POST['msgh'];
$aname=$_POST['aname'];
$pass=$_POST['pass'];
$cheight=$_POST['cheight'];
$cwidth=$_POST['cwidth'];
$prcadmin=$_POST['prcadmin'];
$cas=$_POST['cas'];
$frznick=$_POST['frznick'];
$sm=$_POST['sm'];
$id=$_COOKIE["id"];
//Check if the cookie id is empty
if (!isset($id))
{
header( 'Location: www.techbreeze.in/mychat/chat-add.html') ;
}
//Check if any field is empty and redirect to setup page if empty
if ((isset($cname))&&(isset($nicklen))&&(isset($msglen))&&(isset($pm))&&(isset($msgh))&&(isset($aname))&&(isset($pass))&&(isset($cheight))&&(isset($cwidth)))
{
if ((is_numeric ($nicklen)) && (is_numeric ($msglen))&&(is_numeric($pm))&&(is_numeric($msgh))&&(is_numeric ($cheight))&&(is_numeric ($cwidth)))
{
//Start writting data into the file
$str1=";";
$str2 = ".php";
$str4 = "\n";

$File = $id . $str2;
$fh = fopen($File, 'w') or die("can't open file");

$stringData = "<?php\n";
fwrite($fh, $stringData);

$strt1= "require_once /mychat/src/phpfreechat.class.php;\n";
$stringData = $strt1;
fwrite($fh, $stringData);

$strt1='$params["serverid"] =';
$stringData = $strt1 . $id . $str1 . $str4;
fwrite($fh, $stringData);
fclose($fh);


$strt3 = "$params";
$stringData = $strt3;
fwrite($fh, $stringData);
fclose($fh);
}
else
{
echo "Only numeric Inputs allowed for the fields";
echo "<br><br><br>";
echo "Enter the maximum length of nick";
echo "<br>";
echo "Maximum Lenth of message";
echo "<br>";
echo "Max number of Simultaneous PM";
echo "<br>";
echo "No. of msg to be stored in history";
echo "<br>";
echo "Height of the Chat Room";
echo "<br>";
echo "Width of Chat Room";
echo "<br><br><br>";
echo "Please Fill them up Carefully!";
echo "<meta HTTP-EQUIV='REFRESH' content='6; url= http://www.techbreeze.in/chat-setup.html'>";

}
}
else
{
echo "You Have one or more incomplete Field";
echo "<br>";
echo "Please Fill them up Carefully!";
echo "<meta HTTP-EQUIV='REFRESH' content='2; url= http://www.techbreeze.in/chat-setup.html'>";
}

?>

ok now the error i am getting is
Warning: fclose(): 3 is not a valid stream resource in /home/techbr/domains/techbreeze.in/public_html/mychat/chatcreate.php on line 52 Any ideas as to what i should do and why i am getting this error.

tangoforce
11-15-2011, 02:28 PM
Possibly a file permissions error or if its a windows server and the top level you might not be able to write to it anyway and need to go into a sub directory.

Fou-Lu
11-15-2011, 07:35 PM
I would have expected an error on fopen if we were looking at an issue with the file permissions.
In this case, its simply because you have already closed the resource. You have closed it on line 47 earlier. The error you have should have another error associated with the fwrite on line 52, since the fclose is on line 53.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum