• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

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
0
nchenkin
Asked:
nchenkin
  • 3
  • 2
  • 2
1 Solution
 
maneshrCommented:
nchenkin,

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

From a CGI point of view here is an alternative that you might want to consider.

use / as the directory delimiter.

So in the case of a Windows based client, let say you get C:\hello\new\world you replace all \'s with /'s and then process them.

Using this approach i can see 2 advantages.

1) Regardless of which OS the client is using, you are standardizing on the / as the delimiter.
This will make your code work with any client OS
2) You dont run into the \n problem as the search-n-replace has replaced \ with/

Hope that helps.
0
 
nchenkinAuthor Commented:
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
0
 
maneshrCommented:
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.
0
Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

 
PeeweeCommented:
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";
}
0
 
PeeweeCommented:
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");
0
 
nchenkinAuthor Commented:
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
0
 
maneshrCommented:
nchenkin,

"..Thanks maneshr,..."

You're welcome.

"..Things are working now..."

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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now