#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    61
    Rep Power
    15
    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).]
  2. #2
  3. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    Why don't you use CGI.pm?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    61
    Rep Power
    15
    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).]
  6. #4
  7. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    Okay. Check out -> http://www.perl.com/CPAN-local/modul...rt-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].
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    61
    Rep Power
    15
    I'll try that when I get enough time.

    Thanks for your help!

IMN logo majestic logo threadwatch logo seochat tools logo