Apache vs IIS current directory fro Perl script

Discussion in 'Perl Misc' started by andipfaff, May 8, 2008.

  1. andipfaff

    andipfaff Guest

    Hi there,

    I try to switch from IIS 5 on Win2k to Apache 2.2 on Win2k. None of my
    pictures where shown on the new Server. Some tests showed me that
    whenever I try to check if a file exists with if(-f "pictures/
    photo1.jpg") the files where no longer found. My scripts are located
    in the cgi-bin directory below the document root of the website.

    It seems that a perl script run under IIS always starts with the
    websites document root when using the -f or -e or fopen() function in
    Perl, independent of the location of the perl script. On the other
    hand a Perl script run under Apache is using an absolute root
    directory starting where the script itself is located.

    So if I try to find a file located in /pictures with a script located
    in /cgi-bin I have to use different code:
    IIS: if(-f "pictures/photo1.jpg)
    Apache: if(-f "../pictures/photo1.jpg)

    I want to avoid modifying all scripts for all virtual websites, and I
    want to avoid using absolute paths for the -f function. The first one
    is just too much work, th latter one would make the code unflexible
    and less portable.

    Is there a way to change the behaviour of Apache without touching the
    scripts?

    Thanks in advance
    Andi Pfaff
    andipfaff, May 8, 2008
    #1
    1. Advertising

  2. andipfaff wrote:

    > Is there a way to change the behaviour of Apache without touching the
    > scripts?


    That looks like a question about Apache. You may get better answers in
    an Apache newsgroup or forum.

    alt.apache.configuration

    http://httpd.apache.org/lists.html#http-users

    I expect the answer is yes.

    I'd modify the Perl scripts to pick up a base directory from a common
    configuration file or environment variable. YMMV.

    --
    RGB
    RedGrittyBrick, May 8, 2008
    #2
    1. Advertising

  3. andipfaff wrote:
    > I want to avoid modifying all scripts for all virtual websites, and I
    > want to avoid using absolute paths for the -f function. The first one
    > is just too much work, th latter one would make the code unflexible
    > and less portable.
    >
    > Is there a way to change the behaviour of Apache without touching the
    > scripts?


    Whether there is or not, it would defeat your portability goal.

    You'd better rewrite your scripts, and not rely on paths relative to the
    current directory. One common approach is to have a config file with
    absolute paths.

    $picturepath = 'C:/full/path/to/pictures';
    if ( -f "$picturepath/photo1.jpg" )

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, May 8, 2008
    #3
  4. andipfaff

    Mirco Wahab Guest

    andipfaff wrote:
    > So if I try to find a file located in /pictures with a script located
    > in /cgi-bin I have to use different code:
    > IIS: if(-f "pictures/photo1.jpg)
    > Apache: if(-f "../pictures/photo1.jpg)
    >
    > I want to avoid modifying all scripts for all virtual websites, and I
    > want to avoid using absolute paths for the -f function. The first one
    > is just too much work, th latter one would make the code unflexible
    > and less portable.
    >
    > Is there a way to change the behaviour of Apache without touching the
    > scripts?


    Don't reinforce failure.

    Your pictures are now located somewhere like:

    ...
    if(-f "%ENV{DOCUMENT_ROOT}/pictures/photo1.jpg") {
    ...

    IMHO it's much better to correct your scripts than
    to build pillars around broken-by-design things.

    Regards

    M.
    Mirco Wahab, May 8, 2008
    #4
  5. andipfaff

    Mirco Wahab Guest

    Mirco Wahab wrote:
    >
    > ...
    > if(-f "%ENV{DOCUMENT_ROOT}/pictures/photo1.jpg") {
    > ...

    (wtf)

    correction:
    ...
    if(-f "$ENV{DOCUMENT_ROOT}/pictures/photo1.jpg") {

    ...

    Sorry,

    M.
    Mirco Wahab, May 8, 2008
    #5
  6. Gunnar Hjalmarsson wrote:
    > Whether there is or not, it would defeat your portability goal.
    >
    > You'd better rewrite your scripts, and not rely on paths relative to
    > the current directory. One common approach is to have a config file
    > with absolute paths.
    >
    > $picturepath = 'C:/full/path/to/pictures';
    > if ( -f "$picturepath/photo1.jpg" )

    If you use $ENV{DOCUMENT_ROOT} then you'd be able to port from Windows
    -> Unix too!
    --
    Andrew DeFaria <http://defaria.com>
    5 days a week my body is a temple. The other two, it's an amusement park.
    Andrew DeFaria, May 8, 2008
    #6
  7. andipfaff

    andipfaff Guest

    On 8 Mai, 11:21, Gunnar Hjalmarsson <> wrote:
    > andipfaff wrote:
    > > I want to avoid modifying all scripts for all virtual websites, and I
    > > want to avoid using absolute paths for the -f function. The first one
    > > is just too much work, th latter one would make the code unflexible
    > > and less portable.

    >
    > > Is there a way to change the behaviour of Apache without touching the
    > > scripts?

    >
    > Whether there is or not, it would defeat your portability goal.
    >
    > You'd better rewrite your scripts, and not rely on paths relative to the
    > current directory. One common approach is to have a config file with
    > absolute paths.
    >
    >      $picturepath = 'C:/full/path/to/pictures';
    >      if ( -f "$picturepath/photo1.jpg" )
    >
    > --
    > Gunnar Hjalmarsson
    > Email:http://www.gunnar.cc/cgi-bin/contact.pl


    Thanks for the answer but the portability goal is not met with your
    suggestion. If I change the location where my files are stored (the
    location from the point of view of the filsystem) it does no longer
    work. And I would have dozens of config files with different picture
    paths. The idea with getting the absolute current path while the
    script is running with

    -f "%ENV{DOCUMENT_ROOT}/pictures/photo1.jpg")

    is working fine. Even if I have to change every script but that can be
    done "half" automatically.

    Thanks for your help.
    Andi
    andipfaff, May 13, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. naijacoder naijacoder

    Asp/net with ADirectory(fro authorisation)

    naijacoder naijacoder, Aug 25, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    339
    naijacoder naijacoder
    Aug 25, 2004
  2. Julia
    Replies:
    4
    Views:
    470
    Ken Cox [Microsoft MVP]
    Dec 7, 2004
  3. Steven
    Replies:
    1
    Views:
    594
  4. NoClue
    Replies:
    0
    Views:
    344
    NoClue
    Jun 15, 2005
  5. Replies:
    0
    Views:
    358
Loading...

Share This Page