使用 PHP 下载、编辑和重新上传 FTP 文件


Download, edit and reupload FTP file with PHP

我正在尝试使用PHP从FTP上以形式获取服务器.cfg文件。在此之后,我想在网站上编辑服务器.cfg文件,单击"提交"并在FTP上重新上传编辑后的文件。我做了一些研究,但我仍然得到一些错误。我设法以以下形式获取文件:http://elmazmx77.seventyseven.axc.nl/gameservers2.php.但是,如果我编辑并保存表单,则会出现错误。我的PHP代码:

<?php
$config = array 
( 
'user'  => 'Hunterr', 
'pass'  => '[PASSWORD]', 
'domain'    => 'ycn-hosting.com:21', 
'file'      => '213.108.31.167-27030/etpro/server.cfg',       # relative to 'domain' 
); 
if(isset($_POST['submit'])) 
{ 
$fp = fopen($config['file'],'w'); 
fwrite($fp,stripslashes($_POST['newd'])); 
fclose($fp); 
$ftp = ftp_connect($config['domain']); 
ftp_login($ftp,$config['user'],$config['pass']); 
ftp_pasv($ftp,TRUE); 
ftp_put($ftp,$config['file'],$config['file'],FTP_BINARY); 
ftp_close($ftp); 
} 
?> 
<form width="440" height="440" method="post" action="<?=( $_SERVER['PHP_SELF'] )?>"> 
<textarea name="newd"><?=(       file_get_contents('ftp://'.$config['user'].':'.$config['pass'].'@'.$config['domain'].'/'.$co    nfig['file']) )?></textarea> 
<input type="submit" name="submit" value="Save"> 
</form>

有什么想法吗?(您可以在此处自己查看错误:http://elmazmx77.seventyseven.axc.nl/gameservers2.php)第 13 行的起点为:$fp = fopen($config['file'],'w');所以你知道错误来自哪里。

提前致谢

错误消息指出"警告:fopen(213.108.31.167-27030/etpro/server.cfg) [function.fopen]:无法打开流:没有这样的文件或目录"您正在尝试打开不存在的文件。该文件不在运行脚本的目录中。使用服务器.cfg文件的绝对路径或正确的相对路径。

您可能还想在其中添加一些检查,以查看 fopen 命令是否真的成功了。

GL