in reply to FileParse is NOT working correctly

When the file name is uploaded it includes the entire path but without "/" so it's not parsing correctly when I use "fileparse"

This means you have tested your code only with the Internet Explorer. All other browsers I know just send the filename, not the path. This may bite you as soon as someone does not use the IE.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re^2: FileParse is NOT working correctly
by rrtrems (Initiate) on Apr 21, 2009 at 01:00 UTC
    That is not true. I have used multiple versions of IE and Firefox to test this form.

      It is true, even if you do not want to hear it. Only MS IE sends the entire file name including drive letter and directories, all other browsers I know, including Firefox, Netscape, Opera and Konqueror, send only the file name. Copy the following file into a CGI enabled directory of a webserver as uploadtest.cgi and see for yourself: Open http://server/cgi-bin/uploadtest.cgi, choose any file, and click the submit button.

      #!/usr/bin/perl -Tw use strict; use CGI qw(:all); use Data::Dumper; if (request_method() eq 'POST') { my $f=param('f'); my $info=uploadInfo($f); print header(), start_html(), h1('Upload Metadata'), pre(escapeHTML(Dumper($info))), end_html(); } else { print header(), start_html(), start_multipart_form(), filefield(-name=>'f',-size=>50), submit(), end_form(), end_html(); }

      Result with Firefox 3.0.8:

      $VAR1 = { 'Content-Type' => 'application/octet-stream', 'Content-Disposition' => 'form-data; name="f"; filename="win +.ini"' };

      Result with IE 6.0.2800.1106:

      $VAR1 = { 'Content-Type' => 'application/octet-stream', 'Content-Disposition' => 'form-data; name="f"; filename="C:\ +\WINNT\\win.ini"' };

      OK, let's be paranoid and let's assume Lincoln D. Stein and me added some evil code into CGI.pm just to make your life harder. So let's get rid of CGI.pm and look at the raw, unparsed data. Copy the following script as uploadtest2.cgi into the CGI-enabled directory of the webserver:

      #!/usr/bin/perl -Tw use strict; print "Content-Type: text/html\015\012\015\012"; if ($ENV{'REQUEST_METHOD'} eq 'POST') { print "<html><body><plaintext>"; print while <STDIN>; } else { print '<html><body>', '<form method="post" action="" enctype="multipart/form +-data">', '<input type="file" name="f" size="50">', '<input type="submit">', '</form></body></html>'; }

      Result with FF:

      -----------------------------114782935826962 Content-Disposition: form-data; name="f"; filename="win.ini" Content-Type: application/octet-stream # file content here

      Result with IE:

      -----------------------------7d936e1f40214 Content-Disposition: form-data; name="f"; filename="C:\WINNT\win.ini" Content-Type: application/octet-stream # file content here

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        What I'm telling you is your statement is UNTRUE. I did test in multiple browsers... you told me I didn't. My code works in all of them! Problem solved. My problem was not browser related. It was apparently an operating systems issue. I needed to account for the way the file would be uploaded. "Almut" gave me the code that worked. My issue is resolved.
        "Normally File::Basename will assume a file path type native to your current operating system (ie. /foo/bar style on Unix, \foo\bar on Windows, etc...). With this function you can override that assumption." obviously his form is running on some unix based system and the file being uploaded is microsoft making this an OPERATING SYSTEM issue and not a browser specific issue, even if you don't want to acknowledge it.