Jared Hess wrote:
> 
> I found the code in my script that caused filenames (or pathways) uploaded
> with uppercase letters or spaces in them to have a 0 file size.  The code I
> used to have was:
> 
> ### BEGIN CODE SNIP
> $file = param('filename');
> $file=lc($file);
> $fullfile = $file;
> $file=~s/^.*(\\|\/)//; # STRIP PATHWAY OFF!
> fileext_test(); ###### TESTS FOR CORRECT EXTENTION
> filename_test(); ##### TESTS FOR DUPLICATE NAME ON SERVER
> binmode $fullfile;
> open (SAVEFILE, ">$savedir$file") || dienice("Can't open filehandle: $!\n");
> binmode SAVEFILE;
> while (read($fullfile, $buffer, 1024)) {
> print SAVEFILE $buffer;
> }
> ### END CODE SNIP
> 
> ...which would take my filename and pathway, make them lowercase (so that I
> wouldn't have case differences when I tested for duplicate file names on the
> server-- plus it just looked cleaner to have all lowercase filenames).
> Unfortunately, the lc() function (which simply made my string lowercase)...
> 
> $file=lc($file);
> 
> ...was causing the problem. I commented it out, re-ran my script and files
> with capital letters and spaces uploaded fine. I don't know how this simple
> line made uploaded files have 0 file size, but it did.
> 
> So now I have the same problem when I test for files with duplicate names on
> the server. If I upload files with the names "testfile1.ZIP" and
> "testfile1.zip", they're considered different file names. I don't want this.
> I was all files uploaded to be lowercase (this was why I was using the lc()
> function). Currently, I use this code to test for duplicate names:
> 
> ### Begin Code Snip
> sub filename_test{
>         if (-e "$uploadpath/$file"){
>         dienice ("File couldn't upload. The destination directory already
> contains a file with the same name. Please rename your file, and use your
> browser's Back button to resubmit your file.");
>         exit;
>         }
> return 1;
> }
> ### End Code Snip
> 
> How can I force submitted files to be lowercase and not run into the same 0
> file size problem?

We can't fully evaluate it since we can't see all of the code.

When testing for dup name in filename_test, test if lc $a eq lc $b (where $a 
is say the new file and $b is the old file) or take all of the files in the 
dir and put the lc names into a hash and then see if lc $a exists in the hash
(faster).  That way it will catch any dups ignoring case.  Drop the lc $file 
that you have above and save it for the last minute as in below.

Than when you open the file for write:

change:

open (SAVEFILE, ">$savedir$file") || dienice("Can't open filehandle: $!\n");

to:

my $lcfile = lc $file;  # doing the lc here should only affect the new file you are 
writing
open (SAVEFILE, ">$savedir$lcfile") || dienice("Can't open filehandle: $!\n");

-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   http://www.todbe.com/
  / ) /--<  o // //      Mailto:[EMAIL PROTECTED] http://dbecoll.webjump.com/
-/-' /___/_<_</_</_    http://www.freeyellow.com/members/dbecoll/
_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web

Reply via email to