Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Linux vs. Windows file upload names

Posted on 2002-03-25
7
Medium Priority
?
182 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
[X]
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
  • 3
  • 2
  • 2
7 Comments
 
LVL 16

Accepted Solution

by:
maneshr earned 1000 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
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

618 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