[ic] howto do if file exists

Mike Heins interchange-users@icdevgroup.org
Wed Apr 16 23:45:01 2003


Quoting Marty Tennison (marty@sediva.com):
> On Wed, 2003-04-16 at 18:50, Nicholas Cook wrote:
> > Currently I have the following in my results page.
> > 
> > <td width=86>
> >     <a href="[area [item-code]]">
> >        [if-item-field thumb]
> >           <img border="0" src="thumb/[item-field thumb]">
> >        [else]
> >           <img border="0" src="thumb/80.gif">
> >        [/else]
> >        [/if-item-field]
> >     </a>
> > </td>
> > 
> > My question is how would you do "If file exists" instead of the above 
> > if-field exists?  In other words, I want to test if the image file 
> > exists, and if so display the image.  If not, display the default image.
> > 
> > The other question with this is if I can do a "if file exists" clause, 
> > how resource intensive is that.  If people feel that this would be too 
> > slow, what other solutions do people know of. (The only other one I can 
> > think of is to setup a crontab entry to update specific fields in the 
> > database nightly, according to the contents of specific directories.)
> > 
> > Thank you,
> > Nicholas Cook
> 
> With interchange markup it might look something like this
> 
> [if type=file term="some_dir/some_dir/[item-code].jpg"]
> 	Yep it's here
> [else]
> 	Nope it aint
> [/else]
> [/if]
> 

Yes, this works well and is not too bad for resource usage,
as those read-only directories will just about always be
in cache on a busy system. It will *not* be so good if
you have thousands of files in the directory.

There is also another way in Apache:

    <Location /cat/images/thumb>
	ErrorDocument 404 /cat/images/thumb/80.gif
    </Location>

Not really very portable, as you have to remember to mess with
your Apache configuration. But it works well...if you use .htaccess
it might even transfer with the directory.

-- 
Mike Heins
Perusion -- Expert Interchange Consulting    http://www.perusion.com/
phone +1.513.523.7621      <mike@perusion.com>

Software axiom: Lack of speed kills.