All,

I have a page on our intranet site that is pulling an image from our
corporate web server.  The corporate server & the image I am accessing is
beyond my control.  The image is generated daily and appears to be named
with a timestamp in the file name so therefore the image name changes daily.

On my site I have the page to check if a cookie exists with the image's file
name.  If the cookie is set then the page will create the IMAGE tag using
the file name specified in the cookie.  If the cookie value is not set then
the code will go open the web page on the corporate server, dump the page's
content into an array, and then the array is parsed until a known string is
found and then the image file name can be pulled out and displayed.

Currently the code I have is working.  However, I know that it can/needs to
be improved but I'm not sure what/how to go about implementing the following
improvements:

1) If the image file name doesn't exist go to the corporate web server,
access the page, and parse the page contents until we find the image.  The
problem I currently have is that the page on the corporate site is huge with
several hundred lines of html in the page and the image I need to access is
closer to the bottom of the page.  How do I walk through the contents of the
page searching for the image starting further down the page than from the
beginning if the page?

2) Is there a better way of trying to find/strip the image name in the page
contents than by using the strpos & substr functions?  If so how?

3) Once I've found the image file name, is there then some way that I can
download the image from the corporate site to our local site?  If so, how do
I do this?  If I can download the image locally, then I can rewrite the code
to check for the existence of the file locally before going out and
accessing the corporate site every time.

Code is below.  Thanks in advance

Dave Merritt
[EMAIL PROTECTED]

<%
$Image = $_COOKIE['ImageToday'];
$WebLocation = 'http://www.somesite.com';

if (empty($Image))
{    
    $Find = '<IMG SRC="/archive/images';

    $PageContents = @file($WebLocation);
    
    if (! empty($PageContents))
    {
        while (list ($ArrayNo, $Line) = each ($PageContents))
        {
            $Image = stristr($Line, $Find);
            if ($Image != "")
            {
                $Image = substr($Image, 0, strpos($Image, '" BORDER=0'));
                $Image = substr($Image, strpos($Image, '"') + 1);
                $Image = $WebLocation . $Image;
                %>
                <SCRIPT type= "text/javascript" language="JavaScript">
                <!--
                    document.cookie = "ImageToday=<%echo $Image%>; path=/"
                //-->
                </SCRIPT>
                <A href="<%echo $WebLocation%>">
                    <IMG src="<%echo $Image%>" border="0" alt="Some label">
                </A>            
                <%   
            }        
        }
    }
    else
    {
        %>        
        <P class="text">Unable to display 
            <A href="<%echo $WebLocation%>" class="text">image from
site</A>!
        </P>
        <%    
    }
}    
else
{
    %>
    <A href="<%echo $WebLocation%>"><IMG src="<%echo $Image%>" border="0"
alt="Some label"></A>
    <%
}
%>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to