I am trying to get a server.cfg file from a FTP in a form on my website, using PHP. After this I want to edit the server.cfg file on the website, click 'submit' and reupload the edited file on the FTP. I did some research, but I still get some errors. I've managed to get the file in the form. But if I edit and save the form, I get errors. My PHP Code:
<?php
$config = array
(
'user' => 'Hunterr',
'pass' => '[PASSWORD]',
'domain' => '[HOST]',
'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>
- <?php
- $config = array
- (
- 'user' => 'Hunterr',
- 'pass' => '[PASSWORD]',
- 'domain' => '[HOST]',
- '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>
Any idea's? Line 13 starts at: $fp = fopen($config['file'],'w'); so you know where the errors come from.
Errors:
Warning: fopen(213.108.31.167-27030/etpro/server.cfg) [function.fopen]: failed to open stream: No such file or directory in [LINK] on line 13
Warning: fwrite(): supplied argument is not a valid stream resource in [LINK] on line 14
Warning: fclose(): supplied argument is not a valid stream resource in [LINK] on line 15
Warning: ftp_connect() [function.ftp-connect]: php_network_getaddresses: getaddrinfo failed: Name or service not known in [LINK] on line 17
Warning: ftp_login() expects parameter 1 to be resource, boolean given in [LINK] on line 18
Warning: ftp_pasv() expects parameter 1 to be resource, boolean given in [LINK] on line 19
Warning: ftp_put() expects parameter 1 to be resource, boolean given in [LINK] on line 20
Warning: ftp_close() expects parameter 1 to be resource, boolean given in [LINK] on line 21
Thanks in advance