I use .csv file to keep log whether the file is uploaded to server or not. Log file is as shown in below :
09:40:51,kapilbastu,1001,201407290940041001msg.mp3,201407290940041001vdc.mp3,137,Not_syn 09:44:30,kapilbastu,1001,201407290943351001msg.mp3,201407290943351001vdc.mp3,136,Not_syn 09:46:25,Other,1001,201407290945481001msg.mp3,201407290945481001vdc.mp3,137,Syn 09:47:13,Other,1001,201407290946411001msg.mp3,201407290946411001vdc.mp3,136,Syn 09:47:50,Other,1001,201407290947191001msg.mp3,201407290947191001vdc.mp3,136,Not_syn 11:46:01,kapilbastu,1001,201407291145101001msg.mp3,201407291145101001vdc.mp3,137,Not_syn 13:58:14,kapilbastu,1001,201407291357121001msg.mp3,201407291357121001vdc.mp3,136,Syn
Sometime file is sync but sometime file can't sync due to Internet problem as we can see in the 'G' column of the log file. I need to read this log file and have to upload file *.mp3 one by one. For that i run php script in crontab that have to read file in each line and upload files. If the file is uploaded successfully then only "Not-syn" field need to change to "Syn". If the line has "Syn" already,it do nothing and move to next line.
I wrote following php script:
$a=6;
if (($handle = fopen("/tmp/newfile.csv", "ar+")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($data[$a] == "Not_syn") {
$date = $data[$a - 6];
$from= $data[$a - 5];
$phoneNumber = $data[$a - 4];
$vdc = $data[$a - 3];
$msg = $data[$a - 2];
$postTo = $data[$a - 1];
$flag=upload_function( $date, $from, $phoneNumber, $vdc, $msg, $postTo )
if($flag)
{
$detail = array($date, $from, $phoneNumber, $msg, $vdc, $postTo, "Syn");
fputcsv($handle , $detail);
}
else
{
$detail = array($date, $from, $phoneNumber, $msg, $vdc, $postTo, "Not_syn");
fputcsv($handle , $detail);
}
return true;
}
else
{
$detail = array($date, $from, $phoneNumber, $msg, $vdc, $postTo, "Not_syn");
fputcsv($handle , $detail);
return false;
}
}
}
fclose($handle);
which is rubbish programming. How can i solve this problem ?