corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » Anyone fluent in PHP?


New Topic

New Poll
  Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author Anyone fluent in PHP?
Bart
Member

Registered: 19th Aug 02
Location: Midsomer Norton, Bristol Avon
User status: Offline
10th Dec 08 at 08:56   View User's Profile U2U Member Reply With Quote

im trying to randomly rotate 4 images on my website. Ive found a script that will randomly rotate a single image, but not more than one.
If I copy the code multiple times it shows the same 4 images. Ive created a number of php files and called upon a different php file for each image, but still no different.

The code ive found is:

quote:

$extList = array();
$extList['gif'] = 'image/gif';
$extList['jpg'] = 'image/jpeg';
$extList['jpeg'] = 'image/jpeg';
$extList['png'] = 'image/png';


// You don't need to edit anything after this point.


// --------------------- END CONFIGURATION -----------------------

$img = null;

if (substr($folder,-1) != '/') {
$folder = $folder.'/';
}

if (isset($_GET['img'])) {
$imageInfo = pathinfo($_GET['img']);
if (
isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) &&
file_exists( $folder.$imageInfo['basename'] )
) {
$img = $folder.$imageInfo['basename'];
}
} else {
$fileList = array();
$handle = opendir($folder);
while ( false !== ( $file = readdir($handle) ) ) {
$file_info = pathinfo($file);
if (
isset( $extList[ strtolower( $file_info['extension'] ) ] )
) {
$fileList[] = $file;
}
}
closedir($handle);

if (count($fileList) > 0) {
$imageNumber = time() % count($fileList);
$img = $folder.$fileList[$imageNumber];
}
}

if ($img!=null) {
$imageInfo = pathinfo($img);
$contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ];
header ($contentType);
readfile($img);
} else {
if ( function_exists('imagecreate') ) {
header ("Content-type: image/png");
$im = @imagecreate (100, 100)
or die ("Cannot initialize new GD image stream");
$background_color = imagecolorallocate ($im, 255, 255, 255);
$text_color = imagecolorallocate ($im, 0,0,0);
imagestring ($im, 2, 5, 5, "IMAGE ERROR", $text_color);
imagepng ($im);
imagedestroy($im);
}
}

?>



Does anyone know how to modify the above to suit?
colour_golden
Member

Registered: 24th Feb 08
Location: Hull - UK
User status: Offline
10th Dec 08 at 12:46   View User's Profile U2U Member Reply With Quote

doesnt make sense, how do you rotate one image?
Unless you mean rotate as in landscape to Portrait or do you mean rotate as in slideshow type rotate?

[Edited on 10-12-2008 by colour_golden]
Bart
Member

Registered: 19th Aug 02
Location: Midsomer Norton, Bristol Avon
User status: Offline
10th Dec 08 at 12:58   View User's Profile U2U Member Reply With Quote

randomly rotate, as in, it shows one image, you click refresh and it shows another image.

It does work, but when using it more than once it shows all for of the same images.
AndyKent
Member

Registered: 3rd Sep 05
User status: Offline
10th Dec 08 at 13:13   View User's Profile U2U Member Reply With Quote

I'd chuck all that code in the bin and start over.

Save your images as index1, index2, index3, index4 (for example).

Then generate a random integer between 1 & 4 with $ran_num = rand(1,4);

Then code the path to the image;
$image = 'index'.$ran_num.'.jpg';

Then just get the code to insert $image whereever its required on the page.
Laney
Member

Registered: 6th May 03
Location: Leeds
User status: Offline
10th Dec 08 at 13:37   View User's Profile U2U Member Reply With Quote

quote:
Originally posted by aPk
I'd chuck all that code in the bin and start over.

Save your images as index1, index2, index3, index4 (for example).

Then generate a random integer between 1 & 4 with $ran_num = rand(1,4);

Then code the path to the image;
$image = 'index'.$ran_num.'.jpg';

Then just get the code to insert $image whereever its required on the page.


...or

$image='index'.rand(1,4).'.jpg';

if you're wanting to paste the same code and generate different images each time
AndyKent
Member

Registered: 3rd Sep 05
User status: Offline
10th Dec 08 at 13:41   View User's Profile U2U Member Reply With Quote

Or that, yes

 
New Topic

New Poll

  Related Threads Author Forum Replies Views Last Post
In Car Video Camera Mounts corb General Chat 27 1962
6th Oct 06 at 23:43
by 5chaap2k
 
road tax problem Ste Help Zone, Modification and ICE Advice 7 938
2nd Nov 06 at 23:36
by Ste W
 
Ultimate barn find... Colin General Chat 26 2145
28th Jan 07 at 14:33
by Butler
 
Awesome 700bhp 996 Nurburgring Lap!!! Novaneil General Chat 23 1310
19th Mar 08 at 19:19
by Tex
 

Corsa Sport » Message Board » Off Day » Geek Day » Anyone fluent in PHP? 29 database queries in 0.8329589 seconds