FTP connection / Flash front end

Hello all,

I am in the process of planning a project and I would love some input on the following. I have most of this planned out and really this should be straight forward and not too difficult.

The goal:

Create an air app that will allow internal users to connect to a secure server and upload image file (jpg, png, gif). There are many reasons why I can’t just give them ftp access, there is a lot of trickery that needs to happen after the file is uploaded (it needs to a has code, unix timestamp etc) then there is a second part which is irrelevant to this conversation.

The plan:

Create a front end that will connect to a PHP script that will open an FTP connection and handle file uploads. There will be constant communication between the swf and this php script.

The questions:

When the user opens the swf, the app will tap the PHP script and open a connection (something like below)


function connect($ftp_server, $username, $password)
{
    $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");     
    $login_result = ftp_login ($conn_id, $username, $password);     
    verifyConnection($conn_id, $login_result);
}

function verifyConnection($conn_id, $login_result)
{
    define(conn, $conn_id);
    define(login, $login_result);
    define(wd, "/someworkingdirectory/");    
    define(filename, "somefilepassedin");
    $verify = (!conn || ! login ? connectionError() : connectionSuccess());
}

[LIST]
[*]Now my first question is once I open this connection can other PHP files access this connection? For example can I have another PHP file that does something like below or do I need to have all functions in the same file? Also, let’s say I tap the php file once to connect, if I tap it again does it know what conn is?
[/LIST]


function putFile($f)
{
    $exists = ftp_size(conn, $f);
    if ($exists == "-1")
    {
        if (ftp_put(conn, $f, $f, FTP_ASCII)) 
        {
            echo "successfully uploaded $file
";
        } 
        else 
        {
            echo "There was a problem while uploading 
";
        }
    }
    else
    {
        echo "<br/><br/>Error: The file you are attempting to upload already exists";
    }
}


[LIST]
[*]The second question is how to I handle time outs and things of that nature?
[/LIST]
I guess I am worried that I am either overlooking something or over thinking this.

Also all the above code is just something I have been messing around with, so don’t take it literal but that’s the direction I was going with this.

I only have about 40 hours to complete this so I am looking for a quick yet object oriented/clean approach for version 2.

I hope I was clear, thanks all
Dave