in reply to Using FindBin or CWD from within a CGI program

Possibly OT, but I see a possibility that you need to rethink your question... or, at least, the title portion and some matters which grow out of that.

My surmise is based in part on your comment "I really need to be able to determine where the perl script was executed from..." and in part on what I see as the implication ( in your observation that CWD and CGI report the location as "/." ) that you don't want to save the uploads there. (Also note that the directory from which perl executes and the cgi-bin where your script is stored are not necessarily the same, and may well involve all manner of sym link magic, which is far beyond the scope of this discussion.)

So if you're really looking for answers about how to find and define an appropriate target for uploads, consider this: they might go to a subdirectory of cgi-bin such as /uploads/ *OR* to an .hta-protected directory within your /http-docs/ (or /public-html/ or /http-public/ or /whatever-name/ the admin of your server has defined as the public root -- the highest level directory browseable by the general public).

If you use a protected subdir of /http-docs/, you should be able to give your script a full URL to that subdir; eg "http://www.foo.bar/blivitz/" and append a filename supplied by the user (after some cautious untainting). You probably do NOT want to save the uploads in any directory to which access is otherwise available to the uploader -- simply because it makes some mischief easier.

Alternately (and still hypothesizeing that you're on a shared Apache or similar *nix server from which I've also inferred that you are NOT the admin of the server and that you do not have root priviledges) you might explore your site's root directory -- *EMPHASIS* on "your site's root" because that and the actual root are not the same. Even a simple tool like your ftp client can be used to check your site's root. Many providers will offer a directory named "ftp" or similarly, with a subdir called "incoming" or "uploads" or somesuch. If so, aiming your users' files at /ftp/uploads/ can be an answer to the question I have so brashly hypothesized to be your real issue.

  • Comment on OT: Non-perl -- but question may be the wrong question