使用PHP将行追加到远程文件
你们好吗? 最近,在FTP服务器的帮助下,我试图使用PHP将新行覆盖到远程文件时遇到了一个问题 我有这个功能:使用PHP将行追加到远程文件,php,Php,你们好吗? 最近,在FTP服务器的帮助下,我试图使用PHP将新行覆盖到远程文件时遇到了一个问题 我有这个功能: function addmgusertoConfig($cfgdata) { $dateadd = date('Y-m-d', strtotime("+0 days")); $handle = fopen($cfgdata,'a'); fwrite($handle, 'MG: '.$_POST["user11"].' '.$_POST["pass11"].' # '.$_POST["
function addmgusertoConfig($cfgdata)
{
$dateadd = date('Y-m-d', strtotime("+0 days"));
$handle = fopen($cfgdata,'a');
fwrite($handle, 'MG: '.$_POST["user11"].' '.$_POST["pass11"].' #
'.$_POST["skype"].' '.$_POST["host"].' '.$dateadd." # \n");
fclose($handle);
}
而:
$cfgdata="ftp://USER:PASSWORD@REMOTEHOST/SOMEDIR/THEFILE.txt";
当我通过php发布数据时,我会得到以下错误日志:
[05-May-2018 07:33:24 UTC] PHP Warning:
file_get_contents(ftp://...@remotehost/somedir/thefile.txt): failed to open
stream: operation failed in /home/LOCALUSER/public_html/post_page.php on
line 204
[05-May-2018 07:33:24 UTC] PHP Warning:
fopen(ftp://...@remotehost/somedir/thefile.txt): failed to open stream:
operation failed in /home/LOCALUSER/public_html/functions.php on line 202
[05-May-2018 07:33:24 UTC] PHP Warning: fwrite() expects parameter 1 to be
resource, boolean given in /home/LOCALUSER/public_html/functions.php on
line 203
[05-May-2018 07:33:24 UTC] PHP Warning: fclose() expects parameter 1 to be
resource, boolean given in /home/LOCALUSER/public_html/functions.php on line
204
[05-May-2018 07:33:30 UTC] PHP Warning:
fopen(ftp://...@remotehost/somedir/thefile.txt): failed to open stream:
operation failed in /home/LOCALUSER/public_html/functions.php on line 192
[05-May-2018 07:33:30 UTC] PHP Warning: fwrite() expects parameter 1 to be
resource, boolean given in /home/LOCALUSER/public_html/functions.php on line
193
[05-May-2018 07:33:30 UTC] PHP Warning: fclose() expects parameter 1 to be
resource, boolean given in /home/LOCALUSER/public_html/functions.php on line
194
如何使用给定函数或更好的函数修复此问题
提前谢谢 如果在浏览器中调用URL会发生什么情况?您试图读取的文件不存在。因此,不会创建资源。然后一切都失败了。文件的路径将不同于您在浏览器中看到的路径。而且ftp不是一个安全的协议。您的密码只是散列,所有内容都以明文发送。应该在查看sftp。@stickybit在浏览器的URL中写入时没有发生任何事情。。只是一个空白的白色页面。@JasonK如果FTP不安全,请建议我的代码使用任何修复方法,甚至使用fopen fwrite或sftp连接方法。文件应该是空的吗?