[ic] s/Reg Exps on file paths/headaches/g ;

office.standardprinting.net zack@office.standardprinting.net
Tue, 13 Mar 2001 09:44:41 -0500

I'm working on an upload page, and found the docs on using [value-extended],
etc.  So far, so good.

But the <input type="file" . . . > tag returns a full path from Win clients,
e.g.: F:\folder\file.jpg (Macs dutifully return only the filename, not the
whole path :)

Of course, on Linux, this is not helpful if I want to upload "file.jpg",
preserve its filename, and place it in "uploads/".  The docs don't really
touch on this point (at least, not the ones that I've seen), as they simply
specify the outfile as "junk.upload".

I'm afraid I'm doing a pitiful job at reinventing the wheel.  What seemed
like an easy exercise in Regular Expressions has gone South fast.  I'm
having a hard time dealing with the Windows' path delimiter '\', as *nix
wan't to treat it as a metacharacter.  I've tried quotemeta(), but either
I'm using it wrong or I'm chasing the wrong tail.  The results are always

I'm losing my faith in RegExps.  The existing /admin/do_upload |
/admin/upload_file aren't helping me much.



*** CODE ***
[perl]$filename = CGI->{newfile} ;

"Our path to parse is: ".$filename."\n\n";

$filename =~ s|.*[\\]{1}|| ;

"The filename is: ".$filename."\n\n" ;