Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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 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.

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,311
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    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.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •