I am trying to do a loop on an upload form that looks to see if the file has landed in the destination directory yet and sleeps for 5 seconds each time the file is not found, until after 10 times it forwards to a timeout page. The part of this code intended to loop and go to a timeout page is not working, though it uploads fine and goes to the thanks page if the file is a reasonable size:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1") &&
(isset($_POST['submitted']) && $_POST['submitted'] == "yes" )) {
$filecheck = 1;
while(!file_exists($loaddir."/".$newName) && $filecheck < 10) {
sleep(5);
$filecheck = $filecheck + 1;
clearstatcache();
}
clearstatcache();
if (file_exists($loaddir."/".$newName)) {
$insertSQL = sprintf("INSERT INTO $tablename (name, filename, link, location_d, location_p) VALUES '$username', '$newName', '$loaddir/', '$origin_link', '$location_p')");
$Result1 = mysql_query($insertSQL, $dbset) or die(mysql_error());
if ($_POST['research'] == 'Y' OR $_POST['proj_on'] == 'Y' OR $_POST['dept_on'] == 'Y' OR
$_POST['notification'] == 'Y') {
$insertSQL = sprintf("INSERT INTO table (logon, name, research, proj_on, project, dept_on, department,
text, notification, emails, dirpath, filename)
VALUES ('$logon', '$username', %s, %s, %s, %s, %s, %s, %s, %s, '$loaddir/', '$newName')",
GetSQLValueString($_POST['research'], "text"),
GetSQLValueString($_POST['proj_on'], "text"),
GetSQLValueString($_POST['project'], "text"),
GetSQLValueString($_POST['dept_on'], "text"),
GetSQLValueString($_POST['dept'], "text"),
GetSQLValueString($_POST['text'], "text"),
GetSQLValueString($_POST['notification'], "text"),
GetSQLValueString(implode("<\/option><option>",$_POST['emails']), "text"));
$Result1 = mysql_query($insertSQL, $dbset) or die(mysql_error()); }
$insertGoTo = "thx_page.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo = $insertGoTo."?origin_link=".$origin_link."?".$newName;
}
header(sprintf("Location: %s", $insertGoTo));
die();
} /* end if file exists */
else {
$insertGoTo = "timeout.php?origin_link=$origin_link&location_p=$location_p&filename=$newName
&loaddir=$loaddir&pathdir=$pathdir&research=$research
&proj_on=$proj_on&project=$project&dept_on=$dept_on&dept=$dept
&textsent=$textsent¬ification=$notification&emails=$emails";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
die();
} /* end else */
} /* end if posted */
Can anyone out there help me get this loop to a working state? Thanks many times over --
P.S. I inserted line breaks in the fields list and broke up the long list of URL args to make this post more readable, so that's not the problem.