Click here to get back home

Apache vs IIS current directory fro Perl script

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Apache vs IIS current directory fro Perl script andipfaff 05-08-2008
Posted by andipfaff on May 8, 2008, 3:09 am
Please log in for more thread options
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

Posted by RedGrittyBrick on May 8, 2008, 5:17 am
Please log in for more thread options
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

Posted by Gunnar Hjalmarsson on May 8, 2008, 5:21 am
Please log in for more thread options
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

Posted by andipfaff on May 13, 2008, 2:49 am
Please log in for more thread options
> 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.
>
> =A0 =A0 =A0$picturepath =3D 'C:/full/path/to/pictures';
> =A0 =A0 =A0if ( -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/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

Posted by Mirco Wahab on May 8, 2008, 5:21 am
Please log in for more thread options
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/pictures/photo1.jpg") {
...

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

Regards

M.

Similar ThreadsPosted
current directory name in perl August 14, 2006, 11:53 am
Perl and current directory December 9, 2006, 4:41 am
how to use Perl to rename the filenames and directory names under current and subdirectories recursively? September 1, 2004, 2:37 pm
How to fetch output of some other script in the current running perl script? October 25, 2007, 8:18 am
current directory, practical problem June 17, 2008, 9:42 am
PERL can't open file for logging (world writable directory Windows XP Home/ Active Perl / Apache) November 8, 2006, 5:50 pm
Platypus - Current Working Directory - write files November 5, 2007, 7:06 pm
Re: Platypus - Current Working Directory - write files November 6, 2007, 7:25 am
Platypus - Current Working Directory - write file November 6, 2007, 1:19 pm
Re: Platypus - Current Working Directory - write file November 6, 2007, 1:29 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap