in reply to Re: Cannot open a file using a relative path
in thread Cannot open a file using a relative path

Actually i have an index.html file pointing to cgi-bin/index.pl file
What si my workign directory? And why we even care about whats is the cwd, iam askign to open a file starting from Cocument Root which is / , why apache can locate th file based on that?
  • Comment on Re^2: Cannot open a file using a relative path

Replies are listed 'Best First'.
Re^3: Cannot open a file using a relative path
by ikegami (Patriarch) on Apr 24, 2007 at 21:48 UTC

    My apologies, shigetsu and I did not read your question carefully enough.

    So if I understand clearly now, you used /somefolder/somesubfolder/digest.passwd thinking it would be relative to the DocumentRoot. The catch is that Perl knows absolutely nothing about DocumentRoot. The leading / tells Perl it's an absolute path. While you want to access d:\www\blabla/somefolder/somesubfolder/digest.passwd, you're actually attempting to access d:/somefolder/somesubfolder/digest.passwd.

    It's a bit safer if you don't store your password file in your public web space. Solve two problems with one stone by moving your password file to somewhere outside of your DocumentRoot directory tree.

    In short,

    Cocument Root which is /

    I think you meant "/ is DocumentRoot". If so, that's only the case in Apache's configuration files.

    why apache can locate th file based on that?

    Apache has nothing to do with it. Perl is the one trying to open the file.

      Then i guess somehting like this might work:
      open FILE, ">>$ENV{'DOCUMENT_ROOT'}/folder/subfolder/digest.passwd" or + die $!;
      DocumentRoot = "d:\www"

      I though that Perl was asking apache for paths but now that ima thinking it more and more if Perl asked apache about interpreting '/' and apache said that '/ = "d:\www"' then Perl would have no way of differentiate real hdd paths from apache relative ones.

      But linkign to files dows work in a relative way: look
      print p( {align=>'center'}, a( {href=>'/cgi-bin/vault.pl'}, img{src=>'/data/images/hellas.gif'} ));
      Here Perl can find is own way to determine and opne the file, how come it doesnt need an absolute path here?

      One more thing is that if i move my passwd file to a place outside of my web space aapche sees the i ould be needign absolute paths and this ame script is about to run to 2 different hosts with different os , hence paths. How would i be able to specify the correct path since the paths would differ?

        print p( {align=>'center'}, a( {href=>'/cgi-bin/vault.pl'}, img{src=>'/data/images/hellas.gif'} ));
        Here Perl can find is own way to determine and opne the file, how come it doesnt need an absolute path here?

        Perl never sees those uris (not paths) as anything but strings. Those uris are sent to the web browser as is, never checked or opened.

        The web browser create absolute uris from those relative uris and the uri of the document in which they are found, parses the uris into their components, requests those uris (sending only the path portion of the the absolute uri). Apache converts the partial uris to disk paths with the help of DocumentRoot and serves the files.

        How would i be able to specify the correct path since the paths would differ?

        Well, you could put it in a directory relative to your script, or you could place a configuration file with the location of the file in a directory relative to the script.