tags:

views:

36

answers:

3

Im using PHP code to create a dropshadow effect on images. I have this for-loop which basically gets an images size (width, height) and then adds a 1px drop shadow effect by using a for loop and its size. for example:

 for ($i=1; $i<=$height; $i++){
    $display_table.="<img src='dropShadowLeft.jpg'><br>";
 }

It works flawless on my computer (using wampserver). But when uploaded to the internet, it always skips a couple of these images, so instead of the dropShadow.jpg one of those squares where it says image not found (or whatever depending on browsers) shows instead.

Is the for loop too fast or something?

What do you think?

Thanks

+2  A: 

The for loop isn't too fast. That code generates HTML, and it's the HTML that gets sent to the client. That will take as much time as it needs to transfer (well, unless the whole page times out, but that's another story).

I'm not exactly sure the reason for the error, but I can tell you this is a terrible approach. Your browser has to make a request for every one of those images before it can display them (I think, or is it smart enough to recognize they're the same and cache them?). Use one image and either tile it with CSS, or stretch it (if it's one pixel, it'll look fine). This means you don't have to worry about needless extra requests, it produces cleaner and less HTML markup, and fix the problem.

Mark
It is quite common that using PHP destroys the operation of cache. That is, the images will always be fetched from the server and never from cache. (You would need to generate correct validator headers in order to keep cache working.)
PauliL
A: 

Why don't you use CSS for this?

Try using a full url/path to your image like http://www.yourdomain.com/images/dropShadorLeft.jpg

Ben Fransen
A: 

This sometimes happens on some servers when files names contain spaces in them. Check to make sure that the files not found have no spaces.

Sarfraz