...

View Full Version : random image generates Apache errors



consultant
01-20-2003, 11:08 PM
We have a Javascript for generating an image randomnly from a set of images. We are going nuts because even though the script works in that the images display no problem, we are constantly getting the following error messages in our Apache error log (this is just one for pic2.jpg, we see errors for all the pics 1-19):

[Mon Jan 20 15:03:00 2003] [error] [client 216.119.162.82] File does not exist: /home/httpd/vhosts/sitename.com/httpdocs/pic2.jpg

We are trying to fiure out why even though the script works, sometime the server thinks the client is trying to fetch the object from the root dir instead of the /images/pictures/ subdirectory (the only place where the pictures are located).

Here's the script:

<!-- Begin
// Set up the image files to be used.
var theImages = new Array() // do not change this
// To add more image files, continue with the
// pattern below, adding to the array.

theImages[0] = 'pic1.jpg';
theImages[1] = 'pic2.jpg';
theImages[2] = 'pic3.jpg';
theImages[3] = 'pic4.jpg';
theImages[4] = 'pic5.jpg';
theImages[5] = 'pic6.jpg';
theImages[6] = 'pic7.jpg';
theImages[7] = 'pic8.jpg';
theImages[8] = 'pic9.jpg';
theImages[9] = 'pic10.jpg';
theImages[10] = 'pic11.jpg';
theImages[11] = 'pic12.jpg';
theImages[12] = 'pic13.jpg';
theImages[13] = 'pic14.jpg';
theImages[14] = 'pic15.jpg';
theImages[15] = 'pic16.jpg';
theImages[16] = 'pic17.jpg';
theImages[17] = 'pic18.jpg';
theImages[18] = 'pic19.jpg';
theImages[19] = 'pic20.jpg';

// do not edit anything below this line

var j = 0;
var p = theImages.length;
var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
document.write('<img src="/images/pictures/'+theImages[whichImage]+'" width="180" height="200">');
}

// End -->

We are sure there is no where else on our site that tries to load these pictures. Thanks in advance for any help!

arnyinc
01-21-2003, 07:48 PM
Since it works for you and not for everyone else, maybe your script is not getting evaluated correctly in a certain browser. Have you tested all the common browsers?

I'm just guessing here, but maybe the quotes and apostrophes in the following line cause a problem in certain browsers.



document.write('<img src="/images/pictures/'+theImages[whichImage]+'" width="180" height="200">');


I'm bad (TERRIBLE) with OOP, but maybe you want to either

bring your random number in as a parameter


var whichImage = Math.round(Math.random()*(p-1));
function showImage(whichImage){
document.write('<img src="/images/pictures/'+theImages[whichImage]+'" width="180" height="200">');
}


or declare your random number inside the function instead of globally


function showImage(){
var whichImage = Math.round(Math.random()*(p-1));
document.write('<img src="/images/pictures/'+theImages[whichImage]+'" width="180" height="200">');
}


My last two suggestions don't seem like they would fix the problem you're having, so you might want to just ignore them.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum