Random images as a background in HTML
by Kevin on February 6, 2009
in Random Knowlege
A nice wee gem that Alex Peake informed me was possible. The problem: you want a randomly chosen image as a background but don’t want duplication in your css.
In your css file:
background-image: url('images/background.php');
Create the file referenced above with this code:
<?php
$numofimages = count(glob("*.jpg"));
$imagenum = rand(1, $numofimages);
header("Content-Type: image/jpeg\n");
header("Content-Transfer-Encoding: binary");
$fp=fopen("headerimage". $imagenum .".jpg" , "r");
fpassthru($fp);
?>
and voila, random images as a background with the bonus of being able to throw in a new image without having to do any more coding.
This code assumes that your images are called headerimageX.jpg where X is a number.
Upload Reloaded
I did a bit more hacking of my upload script (note the exension change) to tweak some things and make it more secure. The updated code is available for criticism/comment.
I still consider the script to be in beta. It would be nice if folk could test it and report on any errors you encounter (particularly file size related).
I am blocking php asp and python scripts as they are most likely to run on the server and are capable of owning me (which I do not want happening. What other extensions should be blocked on a Linux server?
Uploading Files
i have hacked up a script to allow folk to upload files to my mirror. Feel free to upload anything that you think others will like, provided it is legally ok to do so under copyright law. Anything that I suspect is not legal will be removed without notice. Files uploaded to the unsorted directory will be moved into more suitable locations.
For the PHP coders out there, here is the code I used. Take the .txt off the file to make it work.
Durrrrrrr
When coding a form that uses POST, it is helpful to use the $_POST variable for looking at the data rather than $_GET.
Need PHP help
Can anyone with some PHP knowlege help me with a little problem? I need a PHP function that grabs the html source from a website and returns the code as a string but I dunno what function to use. I have tried a few functions but nothing works.
Any ideas?