Jump to content

Unable to write data into a file in my server using php


Recommended Posts

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.

:shy: Thanks for the prompt reply i feel stupid now overlooking that neways really gr8 support frm ur side now that my script is running i ran into another trouble. When i am writing data into the file after the first 3 lines i am unable to create a newline

$stringData = '$params["display_pfc_logo"] =false;\n';
		fwrite($fh, $stringData);

prints

$params["display_pfc_logo"] =false;\n

 

any idea why?

:shy: Thanks for the prompt reply i feel stupid now overlooking that neways really gr8 support frm ur side now that my script is running i ran into another trouble. When i am writing data into the file after the first 3 lines i am unable to create a newline

$stringData = '$params["display_pfc_logo"] =false;\n';
		fwrite($fh, $stringData);

prints

$params["display_pfc_logo"] =false;\n

 

any idea why?

 

When you place something in single quotes, it will be just that - a literal value. When you place something in double quotes, it will infer the value of variables rather than the literal variable.

 

Your Code:

$stringData = '$params["display_pfc_logo"] =false;\n';

 

Should Be:

$params['display_pfc_logo'] = false;
$stringData = $params['display_pfc_logo'] . "\n";

 

When dealing with list elements, it's best to keep them outside of quotes altogether, because the escaping requirements can become confusing. Also, stacking (multiple ops in one line), can become confusing - try one assignment per line.

Thank you guys its been really helpful and i have got my script running but now i am into a diff problem, since it is related with this code i am posting it in here. So, here is the problem after the script ran its course it created a chat room which is located at say www.techbreeze.in/mychat/3.php now i want the user to just copy the code and paste it in their site to get the chat room in their pages. So i wrote the code

<html>

<object data=http://www.techbreeze.in/$Filewidth=$cwidth height=$cheight> <embed src=http://www.techbreeze.in/$File width=$cwidth height=$cheight> </embed> Error: Embedded data could not be displayed. </object>

</html>

 

I need a way to post this to the user so that he can copy it. I am unable to do so with the echo function any suggestions?

So, this doesn't work?:

 

<?php
echo "<html> 
<object data=http://www.techbreeze.in/$Filewidth=$cwidth height=$cheight> <embed src=http://www.techbreeze.in/$File width=$cwidth height=$cheight> </embed> Error: Embedded data could not be displayed. </object>
</html>";
?>

 

What are the issues when you do that?

Thought you would want to know how i solved that irritating problem. Thanks for your help but well it was a tough nut to crack didnt get much help frm that manual but I managed a dirty way around hope you enjoy it  :D and after all this is done i would be glad if u could come arnd and give it a look, the final product.. here's the link http://www.techbreeze.in/chat

I think the coding part is ok enough but i suck in CSS and have almost no designing capabilites so do ignore the poor look and give me some ideas i could use to make it look better.

You may finally close this thread the project's completed successfuly thanks to phpfreaks !!! Hats off to u guys.

 

<?php 
echo "&lthtml&gt &ltobject data=http://www.techbreeze.in/";
echo $_COOKIE["File"]; 
echo ' width="630"';
echo ' height= "';
echo $_COOKIE["cheight"];
echo '" &gt ';
echo "&ltembed src=http://www.techbreeze.in/";
echo $_COOKIE["File"]; 
echo ' width="630"';
echo ' height= "';
echo $_COOKIE["cheight"];
echo '" &gt ';
echo "&lt/embed&gt ";
echo "Error: Embedded data could not be displayed. ";
echo "&lt/object&gt ";
echo "&lt/html&gt ";
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.