Php上传文件到服务器目录脚本

I was wondering if someone with more experience than me could take a quick second to have a look over my php script for uploading a file to my server.

I had a simple php script that uploaded my image the root of my server when I called the script in my code like so:

http://server.foo.com/images/uploadToDirectory.php

Now I'm trying to amend it so that I can put the name of a folder at the end with the following call:

 http://server.foo.com/images/uploadToDirectory.php?dir=test_folder

But for some reason my image is only getting sent to the root of the server. I've checked the logic of my c# code so I think it must be something to do with my php script. Could someone please have a look over it and tell me if I'm doing something silly with my code?

    <?
$_SESSION['directory'] = $_POST['directory'];
$uploaddir = './'.$_SESSION['directory'];
$file = basename($_FILES['file']['name']);
$uploadfile = $uploaddir . $file;

print_r($_FILES);

if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
        echo "http://server.ip.address/images/{$file}";
}
else
{
    echo "Didn't Work!!!!";
    }

?>

Please note, I know this is probably a really bad way for me to go about doing what I want to do, but it's the way I've implemented it. My knowledge of PHP isn't very good.

For comparison here is the code to load to the root of the server:

    <?
$uploaddir = './';
$file = basename($_FILES['file']['name']);
$uploadfile = $uploaddir . $file;

print_r($_FILES);

if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
       echo "http://server.ip.address/images/{$file}";
}
else
{
    echo "Didn't Work!!!!";
}
?>

Ok so.. if you invoke your script like this:

http://server.foo.com/images/uploadToDirectory.php?dir=test_folder

Then your script should be:

$uploaddir = './'.$_GET["dir"];

That would collect your URL GET variable "dir".