Relative path wont work when opening a file for writing

S

skieros

open(FILE, ">>/some_folder/some_sub_folder/digest.passwd") or die $!;
print FILE "$user:$realm:" . Digest::MD5::md5_hex("$user:$realm:
$pass") . "\n";
close(FILE);

Hello i have the above code that i have changed from absolute hdd path
to a relative to a web server path, but after the change the file
cannot be opened.

Problem is that cause of the script runnign both in localhost and
remote server
i cant specify the same absolute path so i need some relativity here.

I could use a varibale after determiantion of *where* the scrpt is
running, that is which host, but i want to accomplish it with a
relative path. Is this possible?!
 
M

Mark Clements

skieros said:
open(FILE, ">>/some_folder/some_sub_folder/digest.passwd") or die $!;
print FILE "$user:$realm:" . Digest::MD5::md5_hex("$user:$realm:
$pass") . "\n";
close(FILE);

Hello i have the above code that i have changed from absolute hdd path
to a relative to a web server path, but after the change the file
cannot be opened.

Problem is that cause of the script runnign both in localhost and
remote server
i cant specify the same absolute path so i need some relativity here.

I could use a varibale after determiantion of *where* the scrpt is
running, that is which host, but i want to accomplish it with a
relative path. Is this possible?!

It'll depend on your webserver, but something like

use strict;
use warnings;

my %paths = (
relative => q(some_folder/asdf.txt),
absolute => q(/other_path/some_folder/asdf.txt),
);
my $filepath;

if($ENV{SERVER_NAME} eq 'localhost'){
$filepath = $paths{relative};
}else{
$filepath = $paths{absolute};
}

open my $file,">>",$filepath or die $!;
 
J

J. Gleixner

Why not? What's the error?
It'll depend on your webserver, but something like

use strict;
use warnings;

my %paths = (
relative => q(some_folder/asdf.txt),
absolute => q(/other_path/some_folder/asdf.txt),
);
my $filepath;

if($ENV{SERVER_NAME} eq 'localhost'){
$filepath = $paths{relative};
}else{
$filepath = $paths{absolute};
}

open my $file,">>",$filepath or die $!;

That's fine as long as the path exists and is writable by the user
running the process.
 

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

No members online now.

Forum statistics

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

Latest Threads

Top