in reply to File Upload To Selected Directory

In addition to the items Ovid covered above, which I agree are extremely important and perhaps should take precedence over figuring out this other issue, I have this:

You basically want to do something like this:

open (OUTFILE, ">$basedir/$fileName");
and turn it into this:
open (OUTFILE, ">$basedir/$subdir/$fileName");
where $subdir is the subdirectory you wish to place your files under $basedir. If this directory is not guaranteed to exist, you will want to be sure to create it first:
mkdir("$basedir/$subdir") unless -d "$basedir/$subdir"; open (OUTFILE, ">$basedir/$subdir/$fileName") or die "Could not open $basedir/$subdir/$fileName: $!";
If you're going multiple levels deep, with subdirectories under subdirectories, you'll need to (perhaps recursively) be sure each parent directory is created first, and only then try to save the file to it. Hope this helps.