Need Help to Update a Remote File

Essentially what I’m trying to do is this: I’m trying to create a form where once I hit the “submit” button, the data I put in said form can be effectively appended to an xml file that exists on a remote ftp server that I have access to (but do not own). I’ve accepted the fact that this remote file cannot be appended directly, so I’m going along the method of downloading the file to my computer, appending THAT file, then uploading/overwriting the remote file on the server.

This script would be run from that same remote server, not necessarily in the same folder as the file I’m trying to download.

My issue comes in when I try to download said remote file. This is the code I’ve been trying to use to that end:

[php]

$url = “ftp://”.$user.":".$pass."@".$server.$remoteFile;
$path = ‘@c:/…/…/…/test.xml’;

$fp = fopen($path, ‘w’);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);

$data = curl_exec($ch);

curl_close($ch);
fclose($fp);

[/php]

And when I try to run this I get:

Warning: fopen(@c:/…/…/…/test.xml) [function.fopen]: failed to open stream: Invalid argument in D:\Hosting… on line 19

Now I wouldn’t be surprised if this had anything to do with how I defined my $path directory, so if it’s that I’d appreciate if someone could help me figure out the correct way to type that out. OR if someone could help me with an altogether different way to meet my ends, that would be great as well.

You would be better off databasing the form data then having a webpage that makes the XML file. This is quicker and more reliable than using the curl. You can write to the server you just need to make sure the permissons are set correctly then you have the web page make the XML file, and save it to your site directly then you just download via browser.

Tip for your code: / isnt a windows folder \ is

Regards

So I took your advise about using a database instead (so much better) so after learning how to use MySQL with PHP I now have a new problem, and its actually one I’ve always had issues with in some form or another… so the beginning of my code looks like this:

[php]

$conn=mysql_connect(“SERVER”) or die('Could not connect: ’ . mysql_error());
mysql_select_db(“SPD”, $conn) or die(“Could not select Database”);

[/php]

It cannot connect for whatever reason, but it likely has to do with what I think the server is - so please tell me if I’m thinking of this right.

I’ve placed a copy of the .sdf file within the remote server I talked about earlier, and that is where I’m trying to access it. As such, for “SERVER” I’m putting

ftp://User:[email protected] (this being that remote server)

This is the error I get from this:

“Could not connect: php_network_getaddresses: getaddrinfo failed: No such host is known.”

Help please and thank you.

Wherever you were learning MySQL from is wrong. mysql_connect() @ PHP.Net says:

mysql_connect(“server”, “username”, “password”);

This is the format you should be using, otherwise it will try to get the details from the php.ini file.

The server is completely different from your FTP login info. Your host would have to tell you your MySQL server, username and password.

Sponsor our Newsletter | Privacy Policy | Terms of Service