Search code examples
phpcsscontent-management-systemdynamic-data

How do I edit an external css file with PHP?


I have a page with an image. I want the client to be able to upload a new image into the database and then be able to switch out the image from within the CMS. Once they switch it in the CMS, I want PHP to edit the background image in the external css file.

Is it possible to do that? I know how to have PHP switch out an image tag in the HTML markup, but I would like to be able to edit the external css file to keep my code cleaner.


Solution

  • If you're using Apache, you can also embed PHP code in your CSS files, by adding this to your apache conf:

    AddHandler application/x-httpd-php .css