Search code examples
phpcssftpfwrite

edit css via php not FTP


I'm building a website and like wordpress admin users can edit css style through the website rather than access the css file directly via FTP, how does wordpress load the css file?

I'm guessing it somehow reads the css file and applies it to a textarea box, then the user can edit its contents and save it back to the css file.

UPDATE

I know i can use this to read the file.

  file_get_contents("css_file.css");

But how do I write to it?


Solution

  • You can create a textarea, and inside of that, use method file_get_contents. Something like this:

    <form id="myForm" action="act.php" method="post">
    <textarea form="myForm">
        <?php echo file_get_contents("css_file.css");?>
    </textarea>
    <input type="submit" value="Update">
    </form>
    

    Then, in act.php, you can define the action of opening the CSS file and updating it.
    Hope that helps:) In case you need help in file handling, check out https://www.w3schools.com/php/php_file.asp