$conn = ftp_connect("FTP SERVER") or die("Sorry!<br /> Database is unavailable at the moment!"); // Connecting to remote FTP
ftp_login($conn,"LOGIN","PASS");
ftp_get($conn,"file.sav","directory/name.sav",FTP_ASCII); //Taking file from the server
$file = "file.sav";
/*
file.sav would look like this:
--------------------------
parameter1=12345
parameter2=1234
parameter3=13456
parameter4=134894
parameter5=123
(Numbers are random here)
*/
$handle = fopen($file, 'r+'); //( r+ - Read/Write. Starts at the beginning of the file)
$data = fread($handle, filesize($file)); // Reads the data (hope this works)
if($data)
{
if(stristr($data,"parameter3") != FALSE) // Don't know if this is right
{
//I need to get value of parameter3, and change it to 999 or something..
}
}
//And then it should save the file and upload it to remote FTP server..
ftp_close($conn);//Closing connection
*/
Originally Posted by Chris - X-Host
What are you trying to do with this?
|
mv [old filename] [new filename]
Originally Posted by darkrider366
That's a bit of a waste of Bandwidth...
You could(/should?) use a SSH script instead, ofcourse making sure it's linux. Just run a simple command then. Example: Код:
mv [old filename] [new filename] |
Originally Posted by iLinx
gimme a sec, i'll write you a get and set function
|
function set($data, $key, $value) {
$regex = "/^$key+.+\n/";
$data = preg_replace($regex, "$key=$value\r\n", $data);
return $data;
}
function get($data, $key) {
$data = explode("\n", $data);
$regex = "/$key+=+.+$/";
$f = "";
for($i = 0; $i < count($data); $i++) {
if(preg_match($regex, $data[$i])) {
$f = $data[$i];
break;
}
}
if(is_array($f))
return false;
else {
$regex = "/$key+=/";
$f = preg_replace($regex, '', $f); //comment this line if you would like it to return KEY=VALUE instead of just VALUE
return $f;
}
}
if($data)
{
$data = set($data, "parameter1", 22);
$data = set($data, "parameter3", 62);
fwrite($handle, $data);
}
if($data)
{
echo get($data, "parameter1");
}
Originally Posted by SiJ
Thank u soo much man..
+10 rep.. And one thing: How could I upload it back to the remote FTP server? Should I use ftp_put or what? |