Randomized images from a folder without using PHP?

The number of images in the folder will also be changing and I can't change the file names either.


Yes I can use Javascript, I just can't change the file names of the images.

2 Answers

  • 1 decade ago
    Favorite Answer

    Try this -- it will create a random number between 1 - 100. You can then set up conditional statements to say "If the number is __, display this picture." In this example, there are four pictures in the rotation.

    <script type="text/javascript">

    var randomizer = Math.random() * 100;

    if (randomizer <= 25) {

    document.write('<img src="image_1.jpg" alt="image 1" />');


    else if (randomizer <= 50) {

    document.write('<img src="image_2.jpg" alt="image 2" />');


    else if (randomizer <= 75) {

    document.write('<img src="image_3.jpg" alt="image 3" />');


    else {

    document.write('<img src="image_4.jpg" alt="image 4" />');



    Can you use Javascript? If so, you can create an array referencing the images in the desired folder, and then write a short script that will randomly select one of the array elements to display.

  • ?
    Lv 4
    4 years ago

    in case you opt to permit your purchasers to characteristic a document or a picture: importing documents The <enter> form document will cutting-edge a sparkling field and a "browse" button. Clicking the browse button will enable the person to pick a document to characteristic. Clicking the submit will submit the form to this comparable document. Your "upfiles.Hypertext Preprocessor": <header> <?Hypertext Preprocessor function UploadOne($fname) { $uploaddir = 'uploadedfiles/'; if (is_uploaded_file($fname['tmp_name'])) { $filname = basename($fname['call']); $uploadfile = $uploaddir . basename($fname['call']); if (move_uploaded_file ($fname['tmp_name'], $uploadfile)) $res = "document " . $filname . " became into effectively uploaded and saved.<br>"; else $res = "ought to no longer circulate ".$fname['tmp_name']." to ".$uploadfile."<br>"; } else $res = "document ".$fname['call']." did no longer upload."; return ($res); } ?> </header> <physique> <?Hypertext Preprocessor if ($_FILES['image']['call'] != "") { $res = UploadOne($_FILES['image']); $filname = $_FILES['image']['call']; echo ($res); } ?> <h1>importing documents</h1> <form call="fupload" enctype="multipart/form-records" action="upfiles.Hypertext Preprocessor" approach="submit"> <enter form="document" call="image" /> <enter form="submit" fee="submit" /> </form> </physique> finally: you ought to create a itemizing the place to place the uploaded documents, and that itemizing ought to have permissions set to 0777... (here called "uploadedfiles") (This set of applications works, yet isn't maintain against viruses or "injection": the prevention of those is a miles extra complicated count number!)

Still have questions? Get your answers by asking now.