<?php
//expected data: 45:16.5555;18:50.83722;1;19:30:35;17052015;1;0
//file_path to the saved file.
$file_path = 'uploads/';
//file name of the temp file:
$file_name = $_FILES['uploaded_file']['tmp_name'];
//name of the saved file.
$new_file = $_FILES['uploaded_file']['name']; // or set this variable to 'gps.txt'
//if temp file doesn't exist.
if(!file_exists($file_name)) {
exit('The requested file was not uploaded.');
}
//if the file exists, then get it's contents into a string.
$contents = file_get_contents($file_name);
//test for expected data.
$contents = preg_replace('/[^0-9:.;]/','',$contents);
//append it to the saved file, testing to make sure it saved.
if(file_put_contents($file_path . $new_file,$contents . PHP_EOL, FILE_APPEND) !== FALSE) {
echo 'success.';
}
I send to server gps.text and with script above I only update existing gps.text on server with new line ( not overwriting existing file on server )
so expected line look like this: 45:16.5555;18:50.83722;1;19:30:35;17052015;1;0
I need help, what if I send same text, just last number increasing so it will look like this
old 45:16.5555;18:50.83722;1;19:30:35;17052015;1;0
new 45:16.5555;18:50.83722;1;19:30:35;17052015;1;1
can I replace that same line with new until last number reaches 5, when reaches 5 then delete whole line
example:
current line on server is:
45:16.5555;18:50.83722;1;19:30:35;17052015;1;0
I send new line which is exactly same except last value ( 1 )
45:16.5555;18:50.83722;1;19:30:35;17052015;1;1 <- update existing line
45:16.5555;18:50.83722;1;19:30:35;17052015;1;2 <- update existing line
45:16.5555;18:50.83722;1;19:30:35;17052015;1;3 <- update existing line
45:16.5555;18:50.83722;1;19:30:35;17052015;1;4 <- update existing line
45:16.5555;18:50.83722;1;19:30:35;17052015;1;5 <- delete line from file
update until some line reach last value 5 and then delete it
Anyone can help modify above script ?