Zoran
Zoran

Reputation: 1371

changing website background image from back office?

Customer ask me to build him the following functionality for his website:

Can anyone recomend elegant yet easy to build solution?

I am thinking of adding the image in the database table, and then read from table and apply the background directly to <body> like <body background="<?php echo $mybackground;?>"> but I guess that there should be more elegant solution. Any ideas?

Upvotes: 0

Views: 590

Answers (2)

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201798

The simplest approach might be to use a site-wide style sheet that sets background on body using a fixed filename and set up a simple form uploading a file, which then will be stored on the server, in the appropriate folder, under that fixed filename. The would need to have just a file input field and some authentication (maybe just a simple password). The form could then have some basic checking to see that the file is of an image type.

This assumes that the suitability of the image for background has been checked and is the responsibility of the person who submits it.

There’s a small downside. If the background image is changed infrequently (a usual scenario), normal cache mechanism assign a rather long freshness time to it. This means users may get the old background image from a cache for some time. But if this is serious, you could modify server settings so the background image is set to be non-cacheable or has a short lifetime.

Upvotes: 1

Zach Lysobey
Zach Lysobey

Reputation: 15744

There's not going to be a quick cut-paste snippet to do this.

Assuming you don't want to go with a CMS, you'll have to set up a database, create an html form and some php code to deal with updating the database, etc...

to get you started, google "creating a database with phpmyadmin", and then check out http://php.net/manual/en/book.mysqli.php for the php code to connect to it and run sql scripts against it.

Upvotes: 0

Related Questions