[PHP] Trying to locate an image file name from another site

2002-07-09 Thread Merritt, Dave

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=textUnable to display 
A href=%echo $WebLocation% class=textimage 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




Re: [PHP] Trying to locate an image file name from another site

2002-07-09 Thread Miguel Cruz

On Tue, 9 Jul 2002, Merritt, Dave wrote:
 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.

Can you ask the corporate web site people to insert a distinctive HTML
comment just before the image? It would just take them a second, have no
impact on their users, and make your job much easier.

miguel


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




RE: [PHP] Trying to locate an image file name from another site

2002-07-09 Thread Merritt, Dave

No.  Having any changes made to the corporate server for my ease of use is
not an option -- too much politics involved (my use of open source solutions
in a Microsoft environment!!!).

Dave

-Original Message-
From: Miguel Cruz [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 09, 2002 3:55 PM
To: Merritt, Dave
Cc: PHP General (E-mail)
Subject: Re: [PHP] Trying to locate an image file name from another site


On Tue, 9 Jul 2002, Merritt, Dave wrote:
 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.

Can you ask the corporate web site people to insert a distinctive HTML
comment just before the image? It would just take them a second, have no
impact on their users, and make your job much easier.

miguel

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




Re: [PHP] Trying to locate an image file name from another site

2002-07-09 Thread Kevin Stone

If the filename is in fact a timestamp then you can find it using a brute
force method.  All you need is a for() loop and fopen().  Start your search
at midnight the previous night and add one second to the timestamp each
itteration.  If the fopen() function returns something other than FALSE then
you know you've found a file.  There are only 86400 seconds in a day..
peanuts.  Probably take PHP two minutes to run through, if that.  You could
put the script on a cron job to have it give you the new filename each
morning.  You may even find that the script building the image file is also
on a timer.. so after a few days you may be able to skip the brute force
method and simply predict what the next filename will be.

Hows that sound?

-Kevin


- Original Message -
From: Merritt, Dave [EMAIL PROTECTED]
To: 'Miguel Cruz' [EMAIL PROTECTED]
Cc: PHP General (E-mail) [EMAIL PROTECTED]
Sent: Tuesday, July 09, 2002 2:05 PM
Subject: RE: [PHP] Trying to locate an image file name from another site


 No.  Having any changes made to the corporate server for my ease of use is
 not an option -- too much politics involved (my use of open source
solutions
 in a Microsoft environment!!!).

 Dave

 -Original Message-
 From: Miguel Cruz [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, July 09, 2002 3:55 PM
 To: Merritt, Dave
 Cc: PHP General (E-mail)
 Subject: Re: [PHP] Trying to locate an image file name from another site


 On Tue, 9 Jul 2002, Merritt, Dave wrote:
  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.

 Can you ask the corporate web site people to insert a distinctive HTML
 comment just before the image? It would just take them a second, have no
 impact on their users, and make your job much easier.

 miguel

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



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