Php 文件\u放置\u内容-远程文件创建
我可以在另一个主机和域上创建/写入包含文件内容或fwrite的文件吗 如果可以,应该在该主机上设置哪些权限和其他属性 谢谢..请从 将文件从本地主机上载到任何FTP服务器。 请注意,已使用“ftp\u chdir”而不是放置直接远程文件路径…在ftp\u put中…远程文件应该是唯一的文件名Php 文件\u放置\u内容-远程文件创建,php,Php,我可以在另一个主机和域上创建/写入包含文件内容或fwrite的文件吗 如果可以,应该在该主机上设置哪些权限和其他属性 谢谢..请从 将文件从本地主机上载到任何FTP服务器。 请注意,已使用“ftp\u chdir”而不是放置直接远程文件路径…在ftp\u put中…远程文件应该是唯一的文件名 <?php $host = '*****'; $usr = '*****'; $pwd = '**********'; $local_file = './orderXML/or
<?php
$host = '*****';
$usr = '*****';
$pwd = '**********';
$local_file = './orderXML/order200.xml';
$ftp_path = 'order200.xml';
$conn_id = ftp_connect($host, 21) or die ("Cannot connect to host");
ftp_pasv($conn_id, true);
ftp_login($conn_id, $usr, $pwd) or die("Cannot login");
// perform file upload
ftp_chdir($conn_id, '/public_html/abc/');
$upload = ftp_put($conn_id, $ftp_path, $local_file, FTP_ASCII);
if($upload) { $ftpsucc=1; } else { $ftpsucc=0; }
// check upload status:
print (!$upload) ? 'Cannot upload' : 'Upload complete';
print "\n";
// close the FTP stream
ftp_close($conn_id);
?>
看看这个
将文件从本地主机上载到任何FTP服务器。
请注意,已使用“ftp\u chdir”而不是放置直接远程文件路径…在ftp\u put中…远程文件应该是唯一的文件名
<?php
$host = '*****';
$usr = '*****';
$pwd = '**********';
$local_file = './orderXML/order200.xml';
$ftp_path = 'order200.xml';
$conn_id = ftp_connect($host, 21) or die ("Cannot connect to host");
ftp_pasv($conn_id, true);
ftp_login($conn_id, $usr, $pwd) or die("Cannot login");
// perform file upload
ftp_chdir($conn_id, '/public_html/abc/');
$upload = ftp_put($conn_id, $ftp_path, $local_file, FTP_ASCII);
if($upload) { $ftpsucc=1; } else { $ftpsucc=0; }
// check upload status:
print (!$upload) ? 'Cannot upload' : 'Upload complete';
print "\n";
// close the FTP stream
ftp_close($conn_id);
?>
如果您想专门使用file\u put\u内容,则必须使用远程服务器接受的协议进行上传。例如,如果服务器配置为允许PUT请求,则可以创建HTTP上下文并向服务器发送适当的方法和内容。另一个选项是设置FTPs上下文
中有一个关于如何将其与FTP的流上下文一起使用的示例。请注意,使用的URI方案正在以明文形式传输用户凭据
如果您想专门使用file\u put\u内容,则必须使用远程服务器接受的协议进行上传。例如,如果服务器配置为允许PUT请求,则可以创建HTTP上下文并向服务器发送适当的方法和内容。另一个选项是设置FTPs上下文
中有一个关于如何将其与FTP的流上下文一起使用的示例。请注意,使用的URI方案正在以明文形式传输用户凭据
我编写了一个类似于PHP文件内容的函数,该函数正在写入FTP服务器:
function ftp_file_put_contents($remote_file, $file_string)
{
// FTP login
$ftp_server="my-ftp-server.com";
$ftp_user_name="my-ftp-username";
$ftp_user_pass="my-ftp-password";
// Create temporary file
$local_file=fopen('php://temp', 'r+');
fwrite($local_file, $file_string);
rewind($local_file);
// Create FTP connection
$ftp_conn=ftp_connect($ftp_server);
// FTP login
@$login_result=ftp_login($ftp_conn, $ftp_user_name, $ftp_user_pass);
// FTP upload
if($login_result) $upload_result=ftp_fput($ftp_conn, $remote_file, $local_file, FTP_ASCII);
// Error handling
if(!$login_result or !$upload_result)
{
echo('FTP error: The file could not be written on the remote server.');
}
// Close FTP connection
ftp_close($ftp_conn);
// Close file handle
fclose($local_file);
}
// Usage
ftp_file_put_contents('my-file.txt', 'This string will be written to the remote file.');
我编写了一个类似于PHP文件内容的函数,该函数正在写入FTP服务器:
function ftp_file_put_contents($remote_file, $file_string)
{
// FTP login
$ftp_server="my-ftp-server.com";
$ftp_user_name="my-ftp-username";
$ftp_user_pass="my-ftp-password";
// Create temporary file
$local_file=fopen('php://temp', 'r+');
fwrite($local_file, $file_string);
rewind($local_file);
// Create FTP connection
$ftp_conn=ftp_connect($ftp_server);
// FTP login
@$login_result=ftp_login($ftp_conn, $ftp_user_name, $ftp_user_pass);
// FTP upload
if($login_result) $upload_result=ftp_fput($ftp_conn, $remote_file, $local_file, FTP_ASCII);
// Error handling
if(!$login_result or !$upload_result)
{
echo('FTP error: The file could not be written on the remote server.');
}
// Close FTP connection
ftp_close($ftp_conn);
// Close file handle
fclose($local_file);
}
// Usage
ftp_file_put_contents('my-file.txt', 'This string will be written to the remote file.');