Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old June 28th, 2000, 12:36 PM
stodge stodge is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 61 stodge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
If I have:

$fn = "crogram filesfilename.zip"

How can I extract the filename, and end up with

$fn = "filename.zip"?

Every method I try (including using split), fails as my code "appears" to get confused by the single back slash. This seems a simple thing to do, yet I cant get it right.

Basically I have a form which allows a user to upload a file. But when a file is uploaded from windows, its filename includes the full path, which I dont want.

The perl script I'm using is running under Linux.

Any help appreciated.

Thanks

[This message has been edited by stodge (edited June 28, 2000).]

Reply With Quote
  #2  
Old June 28th, 2000, 09:47 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Why don't you use CGI.pm?

Reply With Quote
  #3  
Old June 29th, 2000, 07:47 AM
stodge stodge is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 61 stodge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
I already am.

Ok, let me rephrase the question.

I have a string containing:

crogram filesfilename.zip

which is obviously the filename for a Windows file, which a user is uploading to my server.

When my Perl CGI script running under Linux receives this filename, it tries to extract the filename (i.e. filename.zip),as it doesnt care about the path.

The problem is my script only sees the first back slash; it sees the second one as f (a special character) and not a back slash, which is obviously wrong. Then if I try to remove the slashes, only the first one is removed.

Does that make sense?

[This message has been edited by stodge (edited June 29, 2000).]

Reply With Quote
  #4  
Old June 29th, 2000, 04:52 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Okay. Check out -> http://www.perl.com/CPAN-local/modules/by-module/File/File-PathConvert-0.85.tar.gz

Or try..
############################################
#!/usr/local/bin/perl
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
}
$| = 1;
$buffer =~ /^(.+)rn/;
$bound = $1;
@pairs = split(/$bound/,$buffer);
@var = split(/rn/,$pairs[2]);
if ($pairs[2] =~ /Content-Type:/) {
$pairs[2] =~ s/^rn.+filename.+[^w.%-]([w.%-]+)"rn(.*rn)rn//;
$pairs[2] =~ s/rn$//;
$file_name = "$pairs[2]";
}
print "Content-type: text/htmlnn";
print "$file_name: $file_namen";
#you can also see what @var gives you by uncommenting the following line..
#print "@var: @varn";
############################################
With this, it could completely replace CGI.pm. If $pairs[2] doesn't give you any value, try to replace it with $pairs[1].

Reply With Quote
  #5  
Old June 29th, 2000, 05:24 PM
stodge stodge is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 61 stodge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
I'll try that when I get enough time.

Thanks for your help!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Extracing win32 filename


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway