Can I use ftp_put to put the variable $bleh into a file?
| SitePoint Sponsor |
Can I use ftp_put to put the variable $bleh into a file?
wouldn't it be easier to use fopen(), frwite(), etc?
Yeah, use fopen.
You're done. On the other hand, if you're doing it remotely, you'll want to do that code, then FTP put file.txt, and then delete the local file.txtPHP Code:<?php
$bleh = 'ALSDJFLAKJFSDAFSD';
$fp = fopen('file.txt', 'w');
fwrite($fp, $bleh);
fclose($fp);
?>I don't think you can open a connection and edit live on the server.. FTP clients support that only by downloading it (to a temp file), and then on close uploading it... it's not in the FTP protocol, as far as I know.
- Nathan
Okay I ripped this from the PHP manual but I get a weird error:
PHP Code://ftp settings - set these!
$ftp_server = "bsa270-memphis.com";
$ftp_user_name = "****";
$ftp_user_pass = "*****";
$destination_file = "IP_Log.txt";
//ftp writing process
if ($file_enabled == TRUE){
// 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 {
echo "Connected to $ftp_server, for user $ftp_user_name";
}
// upload the file
$upload = ftp_put($conn_id, $destination_file, $filename, FTP_ASCII);
// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
}
// close the FTP stream
ftp_close($conn_id);
Warning: ftp_close() expects parameter 1 to be resource, null given in C:\Program Files\Apache Group\Apache2\htdocs\ipftp.php on line 56
that means the connection failed, I believe. Add error_reporting(E_ALL); to the top and itll issue a warning or something if the connection fails(i don't know if !null equates to false.)
you must put ftp_close($conn_id); before the last closing brace.
Bookmarks