PHP 将文本上传到文件


PHP upload text to file

我需要一些HTML功能代码的帮助。

我想从网站上的两个文本框(txtName,txtBody)获取信息,然后使用PHP将这些文本框的内容保存到ftp服务器上的文件中。

有人可以指出我这样做的正确方向吗?

谢谢

文件放置内容可用于完成此操作 正如 Dagon 所说,下面是一个简单的示例。

<?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);
?>

如果你处理ftp那么你必须使用 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);