Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default File::Basename

    From how I understood it file::basename was able to tell figure out the
    filename without path for both windows and UNIX.
    I have an html page that has a form field for uploading a file. When I
    hit the choose button it lets me pick something from my directory. Now
    the filename it returns is the full path surrounded in quotes.

    I have done this with and without the quotes and both the result is
    always the same.

    I am working on an apache server running on Linux. I am using a windows
    xp machine to connect to the server and I am using opera as the browser.

    Here is the code..
    #!/usr/bin/perl -T

    use strict;
    use warnings;
    use CGI;
    use File::Basename;

    my $cgi = new CGI;
    print $cgi->header( "text/plain" );

    foreach my $name ( $cgi -> param ) {
    print "$name:";
    foreach my $value ( $cgi -> param ( $name ) ) {
    print " $value\n";
    }
    }


    #upload file
    my $file = $cgi -> param ( 'file' );
    my $basename = basename $file;
    print "$file\n";
    print "$basename\n";

    #my $fh = $cgi -> upload ( $file );


    Here is the output
    ------
    fname: p
    lname: k
    file: "C:\Documents and Settings\pdk\My Documents\My
    Webs\pelsupply\index.htm"
    "C:\Documents and Settings\pdk\My Documents\My Webs\pelsupply\index.htm"
    "C:\Documents and Settings\pdk\My Documents\My Webs\pelsupply\index.htm"

    Any suggestions?

    Paul Kraus

    Paul Kraus Guest

  2. Similar Questions and Discussions

    1. strange behavior in File::Basename
      I'm using Perl 5.6.1 on Debian Linux 3.0 I noticed the module File::Basename doesn't behave like the shell commands basename/dirname in a special...
    2. File.basename, dirname and split changed in 1.8.0!
      Why did the behaviour of File.basename, File.dirname and File.split change in ruby 1.8.0? The tests below run on 1.6.8( and 1.7.x, I think), but...
    3. #24898 [Opn->Csd]: Basename is inporperly changing the path var
      ID: 24898 Updated by: sniper@php.net Reported By: funyon at funyon dot com -Status: Open +Status: ...
    4. #24898 [NEW]: Basename is inporperly changing the path var
      From: funyon at funyon dot com Operating system: Redhat PHP version: 4CVS-2003-07-31 (stable) PHP Bug Type: Filesystem...
    5. #24678 [Opn->Bgs]: BASENAME function - SUFFIX is case-sensitive
      ID: 24678 Updated by: derick@php.net Reported By: taomyn at hotmail dot com -Status: Open +Status: ...
  3. #2

    Default Re: File::Basename

    Paul Kraus wrote:
    >
    > From how I understood it file::basename was able to tell figure out the
    > filename without path for both windows and UNIX.
    > I have an html page that has a form field for uploading a file. When I
    > hit the choose button it lets me pick something from my directory. Now
    > the filename it returns is the full path surrounded in quotes.
    >
    > I have done this with and without the quotes and both the result is
    > always the same.
    >
    > I am working on an apache server running on Linux. I am using a windows
    > xp machine to connect to the server and I am using opera as the browser.
    >
    > Here is the code..
    > #!/usr/bin/perl -T
    >
    > use strict;
    > use warnings;
    > use CGI;
    > use File::Basename;
    >
    > my $cgi = new CGI;
    > print $cgi->header( "text/plain" );
    >
    > foreach my $name ( $cgi -> param ) {
    > print "$name:";
    > foreach my $value ( $cgi -> param ( $name ) ) {
    > print " $value\n";
    > }
    > }
    >
    >
    > #upload file
    > my $file = $cgi -> param ( 'file' );
    > my $basename = basename $file;
    > print "$file\n";
    > print "$basename\n";
    >
    > #my $fh = $cgi -> upload ( $file );
    >
    >
    > Here is the output
    > ------
    > fname: p
    > lname: k
    > file: "C:\Documents and Settings\pdk\My Documents\My
    > Webs\pelsupply\index.htm"
    > "C:\Documents and Settings\pdk\My Documents\My Webs\pelsupply\index.htm"
    > "C:\Documents and Settings\pdk\My Documents\My Webs\pelsupply\index.htm"
    >
    Hi Paul.

    File::Basename needs to know what filespec format you're using. It makes
    a guess depending on the system you're running on. If you need to process
    filenames from a foreign system you need to tell it what that system is.
    Calling

    fileparse_set_fstype('MSWin32');

    should do the trick.

    HTH,

    Rob


    Rob Dixon Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139