Page 1 of 1

Read files from cache! Is big size image already preloaded?

Posted: Sat Jan 03, 2004 8:08 am
by Gerd
Hallo and happy new year!

I have no idea if the following works. But I guess, here in the forum are the best PHP programmers.

My problem:
For a nice designed page, first I load a low resolution jpg background image (loading time).
Close to the </BODY> tag, I like to ask a function every second, whether a bigger background image (same image, but high res) is already loaded in order to reload the background image. Javascript is not able to read from the cache (under IE, Netscape, Opera). Is PHP able to check, if the file is already in cache? I am not a PHP expert, so can somebody help me?

Thanks in advance.

Posted: Sat Jan 03, 2004 8:37 am
by JAM
No, PHP can't see whats in the cache as PHP is server-side. If any way, javascript sounds like the one to go with...
On how, I'd let javascript gurus answer that...

Posted: Sat Jan 03, 2004 9:07 am
by Gerd
PHP is not able to read files from the clients cache? Why is it possible to read files from any folder of the clients PC? All upload.php work that way... ???

Posted: Sat Jan 03, 2004 9:16 am
by JAM
No rules without certain ways to bend them. If you are producing code using a webserver on your own machine (or even intranet networked), you might have access to the filesystem of that very computer.

As I can't see how your upload.php looks and works, I cannot talk about that one. General fileuploading scripts works in a completely different way that loading images in a browser.

Posted: Sat Jan 03, 2004 1:39 pm
by Gen-ik
There are a number of ways to check if an image has loaded... but like the others say it can only be done client-side as PHP runs on the server.

A very basic way to check if any image has loaded is to use something like this...

Code: Select all

<head>
<script type="text/javascript">

bigImageHasLoaded = false

function checkBI()
&#123;
    if(bigImageHasLoaded)
    &#123;
        alert("LOADED")
    &#125;
    else
    &#123;
        alert("NOT LOADED")
    &#125;
&#125;

</script>
</head>
<body>

<img src="images/myBIGimage.jpg" onload="bigImageHasLoaded=true" alt="" />

<hr />

<a href="JavaScript:checkBI()">Check if BIG image has loaded</a>

</body>
Checking if the image already exists in the Cache though is, as far as I know, not possible.

Posted: Sat Jan 03, 2004 3:25 pm
by Gerd
Thanks for your answer jam, and for your source gen-ik!

Its hard to realize, that NOT everything is possible! As a beginner I thought, that even PHP is able to handle this small cache problem. For webdesigner it would be a big gift to know, when a file is already loaded, already in cache. I learned "nothing is impossible, there is always a way". I am really disappointed that I failed in this case...


Anyway, thanks again!