Apache vs IIS current directory fro Perl script

A

andipfaff

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
 
R

RedGrittyBrick

andipfaff said:
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.
 
G

Gunnar Hjalmarsson

andipfaff said:
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" )
 
M

Mirco Wahab

andipfaff said:
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.
 
M

Mirco Wahab

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

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

...

Sorry,

M.
 
A

Andrew DeFaria

Gunnar said:
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!
 
A

andipfaff

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" )

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top