rick001 Posted November 15, 2011 Share Posted November 15, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/251177-unable-to-write-data-into-a-file-in-my-server-using-php/ Share on other sites More sharing options...
trq Posted November 15, 2011 Share Posted November 15, 2011 Just call fclose once at the end of your script. As it stands, your closing the file then again trying to write to it, then trying to close it again. Quote Link to comment https://forums.phpfreaks.com/topic/251177-unable-to-write-data-into-a-file-in-my-server-using-php/#findComment-1288299 Share on other sites More sharing options...
rick001 Posted November 15, 2011 Author Share Posted November 15, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/251177-unable-to-write-data-into-a-file-in-my-server-using-php/#findComment-1288327 Share on other sites More sharing options...
rick001 Posted November 15, 2011 Author Share Posted November 15, 2011 I got to get it working by writing a newline character seperately but still dont know why it didnt work when i used the earlier code was something wrong in that? :confused: Quote Link to comment https://forums.phpfreaks.com/topic/251177-unable-to-write-data-into-a-file-in-my-server-using-php/#findComment-1288337 Share on other sites More sharing options...
phporcaffeine Posted November 15, 2011 Share Posted November 15, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/251177-unable-to-write-data-into-a-file-in-my-server-using-php/#findComment-1288365 Share on other sites More sharing options...
rick001 Posted November 15, 2011 Author Share Posted November 15, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/251177-unable-to-write-data-into-a-file-in-my-server-using-php/#findComment-1288485 Share on other sites More sharing options...
phporcaffeine Posted November 15, 2011 Share Posted November 15, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/251177-unable-to-write-data-into-a-file-in-my-server-using-php/#findComment-1288486 Share on other sites More sharing options...
rick001 Posted November 16, 2011 Author Share Posted November 16, 2011 The problem with the above code is, instead of treating it as a string and posting the msg; it gets implemented and php tries to load the chat itself rather than send those lines as an output. Quote Link to comment https://forums.phpfreaks.com/topic/251177-unable-to-write-data-into-a-file-in-my-server-using-php/#findComment-1288565 Share on other sites More sharing options...
phporcaffeine Posted November 16, 2011 Share Posted November 16, 2011 Try looking at htmlentities() http://php.net/manual/en/function.htmlentities.php Quote Link to comment https://forums.phpfreaks.com/topic/251177-unable-to-write-data-into-a-file-in-my-server-using-php/#findComment-1288579 Share on other sites More sharing options...
rick001 Posted November 16, 2011 Author Share Posted November 16, 2011 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 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 "<html> <object data=http://www.techbreeze.in/"; echo $_COOKIE["File"]; echo ' width="630"'; echo ' height= "'; echo $_COOKIE["cheight"]; echo '" > '; echo "<embed src=http://www.techbreeze.in/"; echo $_COOKIE["File"]; echo ' width="630"'; echo ' height= "'; echo $_COOKIE["cheight"]; echo '" > '; echo "</embed> "; echo "Error: Embedded data could not be displayed. "; echo "</object> "; echo "</html> "; ?> Quote Link to comment https://forums.phpfreaks.com/topic/251177-unable-to-write-data-into-a-file-in-my-server-using-php/#findComment-1288618 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.