My girlfriend doesn't really like ftp clients, and I don't want to give her full control over the files NOT in her folder. So, I've devised a plan: I'm going to use the php ftp functions so she can just go to the page and upload, and it will go into her folder.
I wrote out a script, but I just have a few questions.
First off, here's the code:
Now, $address, $userid, and $passwd are in the inc.php file, and I think they're pretty self explanatory. index.php has the upload form on it, and it submits to this page. Now, first of all, how do we determine whether or not the file should be ASCII or BINARY? She'll be mostly uploading image files, so BINARY may be the way to go, but what if she uploads a .txt file or something? Then, somehow, we need to recognize this and switch it to ASCII. Is there a way to check that before uploading it?PHP Code:include('inc.php');
$connect = ftp_connect($address) or die("Cannot connect to server");
$login_result = ftp_login($connect, $userid, $passwd) or die("Cannot login to server");
$file = $_REQUEST['file'];
ftp_put($connect, $file, $file, FTP_ASCII);
ftp_close($connect);
Also, how do we specify the folder on the server to upload to? Or is it that this file is in that directory and so it knows to just put the file in that directory?
I haven't tested this code out yet, I wanted to get feedback first: will it even work in the first place?
I also plan on displaying the files in the directory for her, by doing this:
Will that work?PHP Code:$directory_name = ftp_pwd($connect);
$filesArr = ftp_nlist($connect, $directory_name);
foreach ( $filesArr as $value) { echo $value."\n"; }
And then one last thing:
What if a file is uploaded with the same name as a file already in the directory? Is there a way to detect this and add a "2", "3", "4", etc on the end of the filename to prevent errors? Or, even throw back a message saying "Hey, there's already a file with this name?"

