0

I am after some help with some code for a HTML feature.

I am wanting to get information from two textboxes on a web site (txtName,txtBody), and then save the contents of these textboxes to a file on an ftp server using PHP.

Can someone point me in the correct direction to do this?

thanks

1
  • file_put_contents($file,$_POST['txtName']); very raw example Commented May 7, 2012 at 21:16

2 Answers 2

2

File put contents can be used to accomplish this as dagon says, below is a simple example.

<?php
    $file = 'people.txt';
    // Open the file to get existing content
    $current = file_get_contents($file);
    //Assign txtName to variable.
    $name = $_POST['txtName'];
    // Append a new person to the file
    $current .= $name;
    // Write the contents back to the file
    file_put_contents($file, $current);
?>
Sign up to request clarification or add additional context in comments.

Comments

1

If you dealing with ftp then you have to use http://www.php.net/manual/en/function.ftp-fput.php

$file = $_POST['txtName'];
file_put_contents($file, $_POST['txtBody']);
$fp = fopen($file, 'r');
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if (ftp_fput($conn_id, $file, $fp, FTP_ASCII)) {
    echo "Successfully uploaded $file\n";
} else {
    echo "There was a problem while uploading $file\n";
}
ftp_close($conn_id);
fclose($fp);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.