Jump to content

Random


mikemanx2

Recommended Posts

Hi i dont know if im sopost to use php for random images. But if php is the languge can you tell me the right one or if php is right can you help me im trying to put a pat on my website with random images.

Link to comment
Share on other sites

I've been working on a gallery here for a while now so I'll give you the script I have set up on my site. Assuming you have php on your server (because on your site I see that all of your pages are .html), make sure you have a dedicated folder for your images you want to randomly display so only images are in it (no .html or anything else).The only things you need to edit are the top 3 lines (the stuff in UPPERCASE). Then copy the code and paste it in your html where you want it to be. If you want it to take from multiple folders, show thumbnails that have links to the larger images, or have any problems, let me know :)

<?php$dir = "/home/DOMAIN/public_html/RANDOMIMAGESFOLDER";$domain = "http://www.mikemanx.com";$folder = "RANDOMIMAGESFOLDER";$imgs = array();// opens image directoryif (is_dir($dir)) {if ($dh = opendir($dir)) {while (($file = readdir($dh)) !== false) {if(!is_dir($file)) {$imgs[] = $file; }}closedir($dh);}}$rand = array_rand($imgs, 1);$rand_image = $imgs[$rand];echo "<img src=\"$domain/$folder/$rand_image\" border='0' alt='$rand_image' title='$rand_image'/>";?>

Link to comment
Share on other sites

OK But I want to put the random image thing on my front page but my front page is html and it wont show up it will just showup and code in the page.

Link to comment
Share on other sites

the page has to be saved as .php for any php script to work in it unless you change your .htaccess file to set your .php pages have the .html extention.if you want to try that, in your .htaccess file add this:

AddType application/x-httpd-php .php .html

i think that should do it

Link to comment
Share on other sites

well it sounds like you dont have one, so i'll help you out..htaccess file is pretty much a text file made in notepad, but instead of being named htaccess.txt its just .htaccess. so all you have to so is make a text file, paste that code above (AddType application/x-httpd-php .php .html) in it, and save it as .htaccess and upload it to your public_html folder. or if you have cpanel you can make a txt file in there and just save it as .htaccess.

Edited by calvin182
Link to comment
Share on other sites

It dident work... Do you know how to do it with html the random pic thing because i no theres a way because look at some of those site that have the random things on them and there made out of html.

Link to comment
Share on other sites

its probably javascript, which I don't know. but I'm thinking you don't have php enabled on your server if it didn't work.edit: yeah I went back and tested this method and it works. try in the javascript forum or find a new host that supports php as php is a server side language and it must be installed on the server for any php scripts to work.

Edited by calvin182
Link to comment
Share on other sites

My host dus have php enabled i have the bravenet pemem edishion

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...