RE: How to check if a file exists before sending

[email protected]
Newsgroups gmane.network.tux
Message-ID <81D52920E866FC46ACA560F5F127D47C138062@AUSXMPC112.aus.amer.dell.com>
From: "Tom Wood" <[email protected]>
To: <[email protected]>
Subject: How to check if a file exists before sending
Date: Tue, 2 Jul 2002 13:39:56 -0400
Reply-To: [email protected]

> I need to check if a file exists when it is requested
> and if it doesn't exists send another file.
> What is the best way to do this?
> Thanks in advance.

Write a dynamic module, and model it after demo2.c.  Your module should try
and fetch the file in the query string; if it doesn't exist, then send
another file.

Here's a simple diff to show what I'm talking about...

--- demo2.c     Tue Dec  4 04:18:47 2001
+++ redirect.c  Wed Jul  3 13:49:35 2002
@@ -46,8 +46,8 @@
                        req->event = 1;
                        ret = tux(TUX_ACTION_GET_OBJECT, req);
                        if (ret < 0 || req->error) {
-                               write (req->sock, ERROR, ERROR_LEN);
-                               goto abort;
+                               strcpy(req->objectname, "/backup.html");
+                               ret = tux(TUX_ACTION_GET_OBJECT, req);
                        }
                        break;

A sample request would be http://server/redirect.tux?/test.html.  If
test.html exists, send it; otherwise send another file (in this case,
backup.html).

David
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.