Parsing FileName for upload

T

Tore Aursand

I'm not sure that that is so important. I assume that he is using the
basename as the basis of a filename to store the file locally. In that
case, the most important thing is probably that the basename that you
obtain doesn't contain things that are directory separators on the
server's filesystem. Whether or not they are separators on the client's
filesystem is probably of lesser importance.

I guess the OP want to preserve only the filename part of the (eventual)
full path sent from the client.

Thus, one have to know what OS (and maybe browser) the client is using, as
far as I can understand from the OP's post.

Does anyone have - or know of - a list of OS'es and their path separators?
I'm only familiar with '/', '\' and ':'.

With thst in mind, one could try something (...) like this:

if ( $filename =~ m,(.+[/|\\|:])?(.+)$, ) {
$filename = $2;
}
else {
die "'$filename' doesn't seem to be a valid filename!\n";
}
 
J

Joe Smith

Tore said:
BTW: Why do you need to know _if_ there is a full path present?

In case it is not obvious, let me re-state Tore's question.

Why do you need to know _if_ there is a full path present?
Why not call the parse routine always?

A properly written parse routine will return the correct
results even when "only a file name was sent".
-Joe
 
J

Joe Smith

Tore said:
OS'es and their path separators?
I'm only familiar with '/', '\' and ':'.

TOPS-20 PS:<DECUS.LIB.TAPE01>FOOBAR.TXT.1
TOPS-10 DSKB:[13,10,MYSTUF,DECUS,LIB,TAPE10]FOOBAR.TXT
VAX/VMS and IBM/MVS are not like Posix.
-Joe
 
T

Tony McGuire

Joe Smith said:
Why do you need to know _if_ there is a full path present?
Why not call the parse routine always?

A properly written parse routine will return the correct
results even when "only a file name was sent".
-Joe

Joe,

I don't need to know.

I just want the file name reliably.

Tore pointed me to fileparse(), which appears to work. At least for
Linux and Windows, it gives the file name reliably regardless of path
or not.
 
B

Ben Morrow

Quoth Tore Aursand said:
Damn! You're so right. My fault not thinking of that, of course. But
there must be (a) module(s) which is safer than the approached solution?

File::Spec::*

I don't know why these haven't been amalgamated with File::Basename:
they have completely independant path-parsing logic...

Ben
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top