Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Linux vs. Windows file upload names

Posted on 2002-03-25
7
178 Views
Last Modified: 2013-12-25
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
Comment
Question by:nchenkin
  • 3
  • 2
  • 2
7 Comments
 
LVL 16

Accepted Solution

by:
maneshr earned 250 total points
ID: 6894546
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
 

Author Comment

by:nchenkin
ID: 6895022
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
 
LVL 16

Expert Comment

by:maneshr
ID: 6895374
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 5

Expert Comment

by:Peewee
ID: 6896049
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
 
LVL 5

Expert Comment

by:Peewee
ID: 6896060
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
 

Author Comment

by:nchenkin
ID: 6896705
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
 
LVL 16

Expert Comment

by:maneshr
ID: 6897102
nchenkin,

"..Thanks maneshr,..."

You're welcome.

"..Things are working now..."

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

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question