Problem script
I have a script that I'm having to work with at my job and it is not performing consistently. When you load the page you'll see a list of files. Reload the page and you'll see another list of files that is never quite the same (it lists some files that were not listed before and excludes others that used to be there). My understanding of how this script is supposed to work is that it should display a list of files that are not the same between the two locations. When I click on one of the checkboxes and then hit the update button I get the message telling me that the files were uploaded and sometimes they are, but other times they are not. There's one file in particular that just will not update no matter how many times I update it. I did not create this script, but I'm hoping that someone here can tell me what is wrong with it. Thank you.
<?php
$sourcedir = "/home/sunweb/ondeck";
$targetdir = "/home/sunweb/live";
$rsync_path = "/usr/bin/rsync";
$cp_path = "/bin/cp";
if (!$_POST) {
// Make a list of Unsync'd files
print "<h4>Select files and directories go live:</h4>\n";
print "<form method=post action=sync.php>\n<table border=0>\n";
$handle = popen("$rsync_path -rnu $sourcedir/* $targetdir", "r");
while(!feof($handle)) {
$filename = trim(fread($handle, 256));
$filenamewithpath = $sourcedir ."/". $filename;
if (file_exists($filenamewithpath) && $filename != NULL) {
print "<tr><td><input type=checkbox name=files[] ";
print "value=". $filename ."></td><td>". $filename ." </td>";
print "<td>". date("n/d/y H:i:s T", filemtime($filenamewithpath));
print "</td></tr>\n";
}
}
pclose($handle);
print "</table>\n<input type=submit value=Update>\n</form>\n";
} else {
// Copy over the selected files
print "<h4>The following files and directories were updated:</h4>\n<pre>";
for ($i = 0; $i < sizeof($_POST['files']); $i++) {
$sourcefile = $sourcedir ."/". $_POST['files'][$i];
$targetfile = $targetdir ."/". $_POST['files'][$i];
system("$cp_path -uv $sourcefile $targetfile");
}
print "</pre>\n";
}
?> 