Link to home
Start Free TrialLog in
Avatar of nchenkin
nchenkin

asked on

Linux vs. Windows file upload names

Greetings experts,

Not sure of the best place to ask this question, but here we go. I have a simple CGI form that allows the user to upload a file, with the basic <input type="file" ... >.

It works fine, I'm able to get the file on my Linux Apache server, no problem.

But here's the problem: If the client was running on a Linux box, the filename arrives in my CGI script as just the base file name:

"/hello/new/world" arrives as just "world". This is fine because that's all I want, the basename.

BUT, if the client was running on a Windows box it arrives as the fully qualified pathname:

"C:\hello\new\world"

This would be OK if I could easily split the path to get the basename, which I could using "\".  The problem is that "\n" is interpreted as a newline character on the receiving end in my CGI script, which is written in Python.

Certainly, regardless of the CGI language, someone has crossed this bridge before?!

Any thoughts would be appreciated.

Thanks
- Nelson
ASKER CERTIFIED SOLUTION
Avatar of maneshr
maneshr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nchenkin
nchenkin

ASKER

maneshr,

Thanks for the comment. The reason I didn't do this is because I *thought* that the "\n" had already been escaped and arrived at my CGI as a newline. I think this was in error. After your comment I checked it and it looks like  the "\" is still there intact.

Let me do some more checks and then I'll give you the points.

- NC
nchenkin,

".. After your comment I checked  it and it looks like  the "\" is still there intact...."

Aha!! Good catch!!!

"..Let me do some more checks..."

Hopefully you will have a working solution with you soon.
nchenkin,

here's what i'm thinking:

get rid of a new line if it exists with a chomp.
then split on a slash which needs to be escaped.

this i think should do the trick..
regards
Peewee

<input type="file" ... >.


chomp $file;
my @array = split(/\\/,$file);

foreach (@array)
{
     print "array:\t$_\n";
}
nchenkin,

also i'm quite sure this module will be of help to you:

regards Peewee
############


 use File::Basename;
 
           ($name,$path,$suffix) = fileparse($fullname,@suffixlist)
           fileparse_set_fstype($os_string);
           $basename = basename($fullname,@suffixlist);
           $dirname = dirname($fullname);
 
           ($name,$path,$suffix) = fileparse("lib/File/Basename.pm","\.pm");
           fileparse_set_fstype("VMS");
           $basename = basename("lib/File/Basename.pm",".pm");
           $dirname = dirname("lib/File/Basename.pm");
Thanks maneshr,

Things are working now. This actually was what I initially was going to do and didn't really need to ask the question! Your comment made me go back and verify that my first impressions (due to some Python string operations I attempted) were incorrect. So, I am now simply converting all the '\' to '/'.

Pewee,
Thanks for your info as well.

Regards,
Nelson
nchenkin,

"..Thanks maneshr,..."

You're welcome.

"..Things are working now..."

Glad to know you got the solution you were looking for.