Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Apache vs IIS current directory fro Perl script

Reply
Thread Tools

Apache vs IIS current directory fro Perl script

 
 
andipfaff
Guest
Posts: n/a
 
      05-08-2008
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
 
Reply With Quote
 
 
 
 
RedGrittyBrick
Guest
Posts: n/a
 
      05-08-2008
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
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      05-08-2008
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
 
Reply With Quote
 
Mirco Wahab
Guest
Posts: n/a
 
      05-08-2008
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.
 
Reply With Quote
 
Mirco Wahab
Guest
Posts: n/a
 
      05-08-2008
Mirco Wahab wrote:
>
> ...
> if(-f "%ENV{DOCUMENT_ROOT}/pictures/photo1.jpg") {
> ...

(wtf)

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

...

Sorry,

M.
 
Reply With Quote
 
Andrew DeFaria
Guest
Posts: n/a
 
      05-08-2008
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.

 
Reply With Quote
 
andipfaff
Guest
Posts: n/a
 
      05-13-2008
On 8 Mai, 11:21, Gunnar Hjalmarsson <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to fetch output of some other script in the current running perl script? ritugoyal12@gmail.com Perl Misc 4 10-27-2007 03:52 PM
PERL can't open file for logging (world writable directory Windows XP Home/ Active Perl / Apache) PGPS Perl Misc 10 11-14-2006 01:40 AM
JSP Script fro currency convertion Steven Java 1 03-09-2005 03:13 AM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM
How to test speed difference of Perl/Apache and SSI/Apache The Poor Perl Misc 2 09-27-2003 12:26 PM



Advertisments