Working around the fopen() command

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AutumnsDecay
    New Member
    • Mar 2008
    • 170

    Working around the fopen() command

    Hey there.

    I've been implimenting FCKEditor into my clients websites so they can update the text and pictures on their own.

    The way it is currently setup is that you need to 'login' to gain access to the editor. Once the changes are made, the user will click submit and the editor will write (in HTML) what the user wrote out in rich text.

    The way that I have the editor writing to the file is like this:

    I use the PHP fopen command to open the file, fwrite to write the contents to the file and save it, and then fclose to close the file.

    My issue is that my host randomly decided to globally disable the fopen command. This means that none of my clients are able to update their website. Is there a work around to using the fopen command? Here is the script I use on every page. I have editted the password for security reasons.

    [PHP]<?php
    if($_REQUEST['thepassword'] == 'password')
    {
    if(($_REQUEST['content']!=''))
    {
    print basename($_SERV ER['PHP_SELF']) . '<br>';
    $file = fopen(basename( $_SERVER['PHP_SELF']) . '.content', 'w');
    fwrite($file,st ripslashes($_RE QUEST['content']));
    fclose($file);
    print '<b>Saved</b><br/><hr/><br/>';

    $content = file_get_conten ts(basename($_S ERVER['SCRIPT_NAME']) . '.content');
    print $content;
    }else{
    print '<form action="'.$_SER VER['PHP_SELF'].'" method="POST">' ;
    $sBasePath = "fckeditor/";
    $oFCKeditor = new FCKeditor('cont ent') ;
    $oFCKeditor->BasePath = $sBasePath ;
    $oFCKeditor->Width = 660;
    $oFCKeditor->Height = 600;
    $oFCKeditor->Value = file_get_conten ts(basename($_S ERVER['SCRIPT_NAME']) . '.content');
    $oFCKeditor->Enabled= true;
    $oFCKeditor->Create();
    print "<input type='hidden' name='thepasswo rd' value='" . $_REQUEST['thepassword'] . "'/>";
    print '<br/><input type="submit" name="submit" value="Save"/>';
    print '</form>';
    }
    }elseif($_REQUE ST['mode']=='login'){
    print '<b>Please enter password:</b>';
    print '<form action="'.$_SER VER['PHP_SELF'].'" method="POST">' ;
    print '<input type="password" name="thepasswo rd" value=""/>';
    print '<br/><input type="submit" name="submit" value="Login"/>';
    }else{
    $content = file_get_conten ts(basename($_S ERVER['SCRIPT_NAME']) . '.content');
    print $content;
    }
    print '<br clear="all"/><br/><a href="' . $_SERVER['PHP_SELF'] . '?mode=login">' ;
    print '<font color="#dddddd" size="-2">login</font></a>';
    ?>[/PHP]

    If anyone can give me a quick alternative, it would be greatly appreciated, as right now it looks like I may need to redo all of my clients websites, and I simply don't have the time or man power to do that in a timely manner.

    Thanks!
  • AutumnsDecay
    New Member
    • Mar 2008
    • 170

    #2
    Some forums talk about cUrl. Is it a good solution?

    I really need this resolved, as I'm losing money by the minute on this.

    Comment

    • code green
      Recognized Expert Top Contributor
      • Mar 2007
      • 1726

      #3
      You could try file_put_conten ts() .
      But are you sure about what has happened?
      is it not a file permissions issue?

      If you are unable to use files a rewrite using a database may be required

      Comment

      • AutumnsDecay
        New Member
        • Mar 2008
        • 170

        #4
        Yeah, I contacted the people I have the reseller hosting account through, and they said the globally disabled the fopen command on all their servers due to security issues.

        how would I impliment this into a database? I'm not overly familiar with SQL yet, so I'm just in need of a temporary quick fix for the time being.

        Comment

        • code green
          Recognized Expert Top Contributor
          • Mar 2007
          • 1726

          #5
          Try file_put_conten ts()
          They might have forgot about that one
          Write a string to a file (PHP 5)
          int file_put_conten ts ( string filename, mixed data [, int flags [, resource context]] )
          Identical to calling fopen(), fwrite(), and fclose() successively.

          Comment

          • AutumnsDecay
            New Member
            • Mar 2008
            • 170

            #6
            And where would I enter that into my code?

            The exact code is posted above in my original question. If you could help me out that would be greatly appreciated!

            Comment

            • code green
              Recognized Expert Top Contributor
              • Mar 2007
              • 1726

              #7
              Replace the following [PHP]if(($_REQUEST['content']!=''))
              {
              print basename($_SERV ER['PHP_SELF']) . '<br>';
              $file = fopen(basename( $_SERVER['PHP_SELF']).'.content', 'w');
              fwrite($file,st ripslashes($_RE QUEST['content']));
              fclose($file);
              print '<b>Saved</b><br/><hr/><br/>'; [/PHP] with [PHP]if(($_REQUEST['content']!=''))
              {
              print basename($_SERV ER['PHP_SELF']) . '<br>';
              file_put_conten ts(basename($_S ERVER['PHP_SELF']).'.content',
              stripslashes($_ REQUEST['content']));
              print '<b>Saved</b><br/><hr/><br/>'; [/PHP]

              Comment

              • AutumnsDecay
                New Member
                • Mar 2008
                • 170

                #8
                They disabled the file_put_conten ts command as well.

                I have a feeling I'm pretty well screwed, as far as this goes.

                Any alternatives? Again... I just need a quick fix.

                Comment

                • code green
                  Recognized Expert Top Contributor
                  • Mar 2007
                  • 1726

                  #9
                  Tell us who your service provider is so we can avoid ever employing them.
                  The only alternatives I can think of are cURL and fsockopen().
                  fsockopen() returns a file pointer, which you can use with fwrite(), fclose() etc.
                  Open Internet or Unix domain socket connection (PHP 3, PHP 4, PHP 5)
                  resource fsockopen ( string target [, int port [, int &errno [, string &errstr [, float timeout]]]] )
                  I have only used fsockpen with FTP so cannot give exact instructions
                  but it will be something like [PHP]if(($_REQUEST['content']!=''))
                  {
                  print basename($_SERV ER['PHP_SELF']) . '<br>';
                  $file = fsockopen("www. yoursite.com/basename($_SERV ER['PHP_SELF']).'.content'", "80", $errno,
                  >$errstr, 180);
                  fwrite($file,st ripslashes($_RE QUEST['content']));
                  print '<b>Saved</b><br/><hr/><br/>'; [/PHP] You may need more work with this

                  Comment

                  • AutumnsDecay
                    New Member
                    • Mar 2008
                    • 170

                    #10
                    Originally posted by code green
                    Tell us who your service provider is so we can avoid ever employing them.
                    The only alternatives I can think of are cURL and fsockopen().
                    fsockopen() returns a file pointer, which you can use with fwrite(), fclose() etc. I have only used fsockpen with FTP so cannot give exact instructions
                    but it will be something like [PHP]if(($_REQUEST['content']!=''))
                    {
                    print basename($_SERV ER['PHP_SELF']) . '<br>';
                    $file = fsockopen("www. yoursite.com/basename($_SERV ER['PHP_SELF']).'.content'", "80", $errno,
                    >$errstr, 180);
                    fwrite($file,st ripslashes($_RE QUEST['content']));
                    print '<b>Saved</b><br/><hr/><br/>'; [/PHP] You may need more work with this


                    My hosting company is 3ix.com Yeah, don't ever use them. I wish I wasn't.

                    Comment

                    • AutumnsDecay
                      New Member
                      • Mar 2008
                      • 170

                      #11
                      the fsockopen didn't work. And not so much that it didn't work, I got a critical error when I tried to reload the page.

                      I've never used curl, so I'm not sure how to go about doing that. I wouldn't assume it's too hard, though. Am I correct?

                      Comment

                      • nathj
                        Recognized Expert Contributor
                        • May 2007
                        • 937

                        #12
                        Is it possible to move host?

                        Alternatively what was the error you received? Post that and we may be able to assist further.

                        I must admit it sounds like the host is a bit over-cautious and should be avoided. Also a database re-write may be the ultimate best option,

                        As for dealing with the client on this, I assume there is a client, I suggest being honest with them and explaining the situation. Most people like the up-front approach and it can often pay dividends in terms of recommendations and while most people like few people really deliver it - a company I worked for once discovered this the hard way,

                        Cheers
                        nathj

                        Comment

                        Working...