Ok, i am quite new to php and i am trying to create an application that allow two clients to access a server simultaneously. i have manged to write the code below but i keep getting errors and i think its probably because i have two form actions on the same page. please help if you can, thank you
<?php
session_start();
if (!isset($_POST['SubmitForm'])) { // if page is not submitted to itself echo the form
?>
<form action="connection.php" method="POST">
<table>
<tr>
<td>FTP Server:</td>
<td><input type="text" value="clancy.dreamhost.com" name="ftp_server"></td>
</tr>
<tr>
<td>Username:</td>
<td><input type="text" value="yusufup" name="ftp_user_name"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" value="yu$uf123" name="ftp_user_pass"></td>
</tr>
<tr>
<td><input type="submit" name="SubmitForm" value="CONNECT"></td>
</tr>
</table>
</form>
<?php
} else
{
$ftp_server = $_POST["ftp_server"];
$ftp_user_name = $_POST["ftp_user_name"];
$ftp_user_pass = $_POST["ftp_user_pass"];
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
session_start();
session_register('ftp_user_name');
echo "Connected to $ftp_server, for user $ftp_user_name";
echo "<br />";
echo "<br />";
}
}
?>
<?php
if (!isset($_POST['Submitupload'])) { // if page is not submitted to itself echo the form
?>
<form action="<?php echo $PHP_SELF;?>" method="POST">
<table>
<tr>
<td>Local (client) File Location:</td>
<td><input type="file" name="source_file" value="C:\Documents and Settings\admin\My Documents\uploads\sas.txt"></td>
</tr>
<tr>
<td>Remote (server) File Location:</td>
<td><input type="text" name="destination_file" value="/yusuf.smthakur.com/sas.txt"></td>
</tr>
<tr>
<td><input type="submit" name="Submitupload" value="UPLOAD"></td>
</tr>
</table>
</form>
<?php
} else
{
$source_file = $_POST["source_file"];
$destination_file = $_POST["destination_file"];
// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// check if source file exist
if (!$source_file) {
echo "Local File $source_file Does Not Exist!";
echo "<br />";
echo "<br />";
exit;
} else {
echo "File '$source_file' Exists";
echo "<br />";
echo "<br />";
}
// check if destination path exist
if (!$destination_file) {
echo "Remote Path '$destination_file' Does Not Exist!";
echo "<br />";
echo "<br />";
exit;
} else {
echo "Remote Path '$source_file' Exists";
echo "<br />";
echo "<br />";
}
// check upload status
if (!$upload) {
echo "FTP upload has failed!";
echo "<br />";
echo "<br />";
$upload_link = "<a href='uploadftpform.php'>CLICK HERE</a>";
echo "IF YOU WANT TO TRY AGAIN PLEASE $upload_link";
} else {
echo "Uploaded '$source_file' to '$ftp_server' as '$destination_file'";
echo "<br />";
echo "<br />";
$upload_link = "<a href='uploadftpform.php'>CLICK HERE</a>";
echo "$upload_link IF YOU WANT TO UPLOAD ANOTHER FILE";
echo "<br />";
echo "<br />";
$download_link = "<a href='downloadftpform.php'>CLICK HERE</a>";
echo " TO DOWNLOAD A FILE FROM A SERVER PLEASE $download_link";
}
}
?>