|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
If I have:
$fn = "c rogram 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).] |
|
#2
|
|||
|
|||
|
Why don't you use CGI.pm?
|
|
#3
|
|||
|
|||
|
I already am.
Ok, let me rephrase the question. I have a string containing: c rogram filesfilename.zipwhich 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).] |
|
#4
|
|||
|
|||
|
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]. |
|
#5
|
|||
|
|||
|
I'll try that when I get enough time.
Thanks for your help! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Extracing win32 filename |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|