>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.

I assume it's not as simple as the year/month/day...

They crammed in the hour minute and seconds as well???

Cuz if it's YYYYMMDD.jpeg, just do:

  $filename = date('Ymd') . ".jpg";
  # Snag $filename

>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?

Look at the basic structure of their HTML.

Is there any comment or TABLE tag or something that's always right before
that IMG tag?

If, so, you can probably do:

  $html = file('corporate.com');
  $html = implode('', $html);
  $html = explode('SOMETHING UNIQUE HERE', $html);

At this point, the IMG tag will always be in the same place in the $html

Might be $html[7] or $html[53] but it will be there.

Also, you can probably just do a single substr() at that point to get the

>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.

Oh, yeah, definitely cache the image.

  $file = file("corporate.com/$image.jpg");
  $image = implode('', $file);
  $cache = fopen("corporatecache.jpg", 'w') or die("Couldn't opne image for
  if ($cache){
    $wrote = fwrite($cache, $image);
    if ($wrote != strlen($image)){
      die("Only wrote $wrote bytes of " . strlen($image));

You'll need to make corporatecache.jpg writeable by PHP.

That's not good...

Ideally, you'd have that *outside* the web tree, and then use PHP to suck it
in again, and check that it "looks like" an image before you do that.  Just
call http://php.net/getimagesize on it, and if that says it's a JPEG, that
should be a pretty good check.

Like Music?  http://l-i-e.com/artists.htm

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

Reply via email to