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.
Page 1 of 3 123 LastLast
Results 1 to 15 of 31
  1. #1
    Regular Coder ttttt's Avatar
    Join Date
    Oct 2005
    Posts
    372
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating an editable style sheet

    Hi,
    I'm trying to create a script that opens a css style sheet and inside a form field, inserts the data from the style sheet, so that it can be edited as a whole. I'm also trying to have a submit button that writes the whole thing back to the file.
    I know to open the file, I need to use fopen(), but that's about as far as my knowledge spreads. And I also know that the script isn't unique to a css stly sheet but could be used for any file.
    I would appreciate some help with my problem greatly,
    Thanks,
    ttttt
    http://openoffice.org/- Microsoft Office without the Microsoft.
    [home page][forum]
    Versatile, free software

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    PHP Code:
    <?php
    $file 
    $_GET['file'];
    $css file_get_contents($file);
    ?>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <textarea name="css"><?php echo $css?></textarea>
    <input type="hidden" name="file" value="<?php echo $file?>" />
    <input type="submit" />
    </form>
    <?php
    if (isset($_POST['css']) && isset($_POST['file'])){
    $file $_POST['file'];
    $css $_POST['css'];
    $f_handle fopen($file'w+');
    fwrite($f_handle$css);
    }
    ?>

  • #3
    Regular Coder ttttt's Avatar
    Join Date
    Oct 2005
    Posts
    372
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the quick reply, but when I run the script, I get an error on the line:
    PHP Code:
    fwrite($f_handle$css); 
    Can you help?
    Also, where do I put the path to the file and can I put it as an URL or do I have to use a server path?
    Thanks,
    ttttt
    http://openoffice.org/- Microsoft Office without the Microsoft.
    [home page][forum]
    Versatile, free software

  • #4
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    PHP Code:
    <?php
    //you know where the CSS is, so no need to let the user choose the file
    $file='/var/www/mysite/css/style.css';

    //perhaps confusingly, deal with the submission first
    if(isset($_POST['the_css'])) {
      
    $fp=fopen($file,'w+'); //open the file for *w*riting
      
    $fwrite($fp,$_POST['css']);  //write the contents
      
    fclose($fp); //remember to close the file
    }


    //to display the form
    $css=file_get_contents($file);  //read in the file contents

    //no need for php to get in the way for a while...
    ?>
    <form action="" method="post">
    <textarea rows="10" cols="40" name="the_css">
    <?php echo $css?>
    </textarea>
    <input type="submit" value="Submit" />
    </form>
    the file specified in $file must be writable by the web-server.
    Accepting the file location from the user, is a really really stupid thing to do.
    Remember though, that people could put things in the CSS that you might not want them to.

  • #5
    Regular Coder ttttt's Avatar
    Join Date
    Oct 2005
    Posts
    372
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I still get this error:
    Warning: fopen(http://versa-soft.com/css.css) [function.fopen]: failed to open stream: HTTP wrapper does not support writeable connections. in
    public_html/admin/css/editcss.php on line 29
    Fatal error: Call to undefined function: () in public_html/admin/css/editcss.php on line 30
    This error appears when the page is submitted. The inclusion of the css file works fine though.
    Thanks for the help,
    ttttt
    http://openoffice.org/- Microsoft Office without the Microsoft.
    [home page][forum]
    Versatile, free software

  • #6
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    as my example showed, it needs to be a file-system location, not a url.

  • #7
    Regular Coder ttttt's Avatar
    Join Date
    Oct 2005
    Posts
    372
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is a really stupid question:
    How do I get to the public_html directory with a filesystem?
    Thanks,
    ttttt
    http://openoffice.org/- Microsoft Office without the Microsoft.
    [home page][forum]
    Versatile, free software

  • #8
    Regular Coder ttttt's Avatar
    Join Date
    Oct 2005
    Posts
    372
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, I've found out the last question, but I still get errors. I've totally changed the file permissions and I tried ignoring the errors, but then it totally wipes my style sheet.
    Thanks for all of the help,
    ttttt
    http://openoffice.org/- Microsoft Office without the Microsoft.
    [home page][forum]
    Versatile, free software

  • #9
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    it depends.
    typically, you'll have:
    /home/ttttt/public_html
    (where ttttt is the username you log in with).
    typing 'pwd' at a command line will tell you...think this will work with ftp as well as shell access.
    if you're using a gui ftp client, then there must be some way of determining the current directory...

  • #10
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    without giving the errors, it's really difficult to help...

  • #11
    Regular Coder ttttt's Avatar
    Join Date
    Oct 2005
    Posts
    372
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The error is:
    Fatal error: Call to undefined function: () in /home/ttttt/public_html/admin/css/editcss.php on line 30
    Thanks,
    ttttt
    http://openoffice.org/- Microsoft Office without the Microsoft.
    [home page][forum]
    Versatile, free software

  • #12
    Regular Coder ttttt's Avatar
    Join Date
    Oct 2005
    Posts
    372
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The thought suddenly dawned on me, I'm only using PHP 4. Does this make a difference when fdealing with the errors?
    Thanks,
    ttttt
    http://openoffice.org/- Microsoft Office without the Microsoft.
    [home page][forum]
    Versatile, free software

  • #13
    Regular Coder
    Join Date
    Aug 2006
    Location
    UK, London, Dartford
    Posts
    221
    Thanks
    3
    Thanked 14 Times in 14 Posts
    Have you chnaged the permissions? to 777?

  • #14
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    typo on my part,
    PHP Code:
    $fwrite($fp,$_POST['css']);  //write the contents 
    should have been
    PHP Code:
    fwrite($fp,$_POST['css']);  //write the contents 

  • #15
    Regular Coder ttttt's Avatar
    Join Date
    Oct 2005
    Posts
    372
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It still doesn't work.
    No PHP errors appear, but it doesn't write the style sheet, it doesn't wipe totally.
    So far, I am using this code:
    PHP Code:
    <?php
    //you know where the CSS is, so no need to let the user choose the file
    $file='/home/ttttt/public_html/css.css';

    //perhaps confusingly, deal with the submission first
    if(isset($_POST['the_css'])) {
      
    $fp=fopen($file'a+');  //open the file for *w*riting
      
    fwrite($fp,$_POST['the_css']);  //write the contents
      
    fclose($fp); //remember to close the file
    }


    //to display the form
    $css=file_get_contents($file);  //read in the file contents

    //no need for php to get in the way for a while...
    ?>
    <form action="" method="post">
    <textarea rows="10" cols="40" name="the_css">
    <?php echo $css?>
    </textarea>
    <input type="submit" value="Submit" />
    </form> </p>
    Thanks,
    Last edited by ttttt; 08-31-2006 at 06:46 PM.
    ttttt
    http://openoffice.org/- Microsoft Office without the Microsoft.
    [home page][forum]
    Versatile, free software


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

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