0

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.

1

3 Answers 3

3

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
Sign up to request clarification or add additional context in comments.

1 Comment

Is this what you are referring to? net.tutsplus.com/tutorials/php/…
0

You can use the file access functions to permanently change it or, probably easier, make the CSS file itself a PHP script and put the logic in there for deciding how the CSS is to be created. Make sure to set the caching rules appropriately for the CSS file.

Comments

0

Adding to Ben and Sydius's answer which generates the dynamic CSS file.

How about having a seperate PHP driven CSS that supercedes the current one you have?

You can also manipulate it to avoid persistent cache of the older image by manipulating the CSS's URI.

 <link rel="stylesheet" href="path/to/sitelevel.css">
 <link rel="stylesheet" href="path/to/background-switcher.css.php?cache-buster123">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.