Beefy Boxes and Bandwidth Generously Provided by pair Networks Ovid
go ahead... be a heretic
 
PerlMonks  

CGI Re: Paths in Perl

by andye (Curate)
on Sep 05, 2001 at 13:51 UTC ( [id://110291]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Paths in Perl

'course, there's a different issue if you're writing a CGI script which accepts a file upload.

Assuming you want to extract the filename from the pathname, I've been known to use something along the lines of this:

my ($filename) = ($pathname =~ m|[/\\:]([^/\\:]+)$|);
but if anyone has a better solution then I'd be interested to hear it.

andy.

Replies are listed 'Best First'.
Re: CGI Re: Paths in Perl
by rob_au (Abbot) on Nov 15, 2002 at 20:36 UTC
    In the CGI::Upload module, the following code was used to parse the full pathname of the uploaded file - This code makes use of HTTP::BrowserDetect to detect the client operating system from the sent HTTP headers and set the parse behaviour of File::Basename accordingly.

    The pertinent code in question ...

    use CGI; use File::Basename; use HTTP::BrowserDetect; sub _handle_file { my ($self, $param) = @_; my $cgi = $self->query; # Determine and set the appropriate file system parsing routines + for the # uploaded path name based upon the HTTP client header informati +on. fileparse_set_fstype( sub { my $browser = HTTP::BrowserDetect->new; return 'MSWin32' if $browser->windows; return 'MacOS' if $browser->mac; $^O; } ); my @file = fileparse( $cgi->param($param), '\.[^\.]*' ); # Return an undefined value if the file name cannot be parsed fr +om the # file field form parameter. return undef unless $file[0]; . . . }

     

    perl -e 'print+unpack("N",pack("B32","00000000000000000000000111100010")),"\n"'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://110291]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.