[ic] howto do if file exists

Marty Tennison interchange-users@icdevgroup.org
Wed Apr 16 22:23:00 2003


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]


With embeded perl, maybe like this

[perl]

my $file = $Tag->file("some_dir/some_dir/[item-code].jpg");

if ( $file ) {
  $a = "yippie";
}else{
  $a = "darn";
}

return $a;

[/perl]


-- 
Marty Tennison <marty@sediva.com>