Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Apache vs IIS current directory fro Perl script

5 views
Skip to first unread message

andipfaff

unread,
May 8, 2008, 3:09:34 AM5/8/08
to
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

RedGrittyBrick

unread,
May 8, 2008, 5:17:39 AM5/8/08
to
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

Mirco Wahab

unread,
May 8, 2008, 5:21:35 AM5/8/08
to
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.

Gunnar Hjalmarsson

unread,
May 8, 2008, 5:21:22 AM5/8/08
to
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

Mirco Wahab

unread,
May 8, 2008, 5:24:42 AM5/8/08
to
Mirco Wahab wrote:
>
> ...
> if(-f "%ENV{DOCUMENT_ROOT}/pictures/photo1.jpg") {
> ...
(wtf)

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

...

Sorry,

M.

Andrew DeFaria

unread,
May 8, 2008, 10:38:01 AM5/8/08
to
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
5 days a week my body is a temple. The other two, it's an amusement park.

Sherman Pendley

unread,
May 8, 2008, 11:20:37 AM5/8/08
to
andipfaff <andrea...@swissonline.ch> writes:

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

Maybe. If so, you'd do it the same way whether your scripts were in Perl,
Python, Ruby, or whatever. Your question is about Apache, not Perl.

sherm--

--
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net

andipfaff

unread,
May 13, 2008, 2:49:10 AM5/13/08
to

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

0 new messages