This is what I ended up doing:
if(isset($_REQUEST["grab"]) && isset($_REQUEST["drop"]) && isset($_REQUEST["file_ref"]))
{
$outcome = "";
$steps = array();
//conditionals for stepping through the ftp process. Retry values are for the subsequent conditional.
$retry = false;
if($steps["Maximum retry attempts reached."] = ($retry_attempt < $max_retrys))
{
$retry = true;
if($steps["FTP connection to host server/port failed."] = @ftp_connect($ftp["host"], $ftp["port"]))
{
$retry = false;
if(current($steps) && $steps["FTP login unsuccessful."] = @ftp_login(current($steps), $ftp["user"], $ftp["password"]))
{
$retry = false;
if(current($steps) && $steps["File not found on local server for upload."] = @filesize(urldecode($_REQUEST["grab"])))
{
$retry = true;
if(current($steps) && $steps["File upload failed during transfer."] = @ftp_put($steps["FTP Host Connect"],urldecode($_REQUEST["drop"]),urldecode($_REQUEST["grab"]), FTP_BINARY))
{
$filesize = array();
$remote_size = get_remote_size($ftp["depository_url"] . urldecode($_REQUEST["file_ref"]));
$filesize["remote"] = $remote_size["size"];
$filesize["local"] = filesize(urldecode($_REQUEST["grab"]));
$retry = true;
if(current($steps) && $steps["Local and remote file sizes do not match. File not verified."] = ($filesize["remote"] == $filesize["local"]))
{
$outcome = "<span class='success'>" . urldecode($_REQUEST["file_ref"]) . "</span> uploaded successfully. [<img src='checkbox.gif' alt='excellent! file verified'>] File Verified (<span class='filesize' style='display: none'>" . $filesize["local"] . "</span>" . number_format($filesize["remote"]/1024/1024, 2) . "mb)"
}
}
}
}
}
}
foreach($steps as $key => $val) //loop through steps, see if there was a false - failed - conditional. If so, also add retry if retry checks out true.
{
if(!$val)
{
$outcome = !$val?"<span class='failed_file'>" . urldecode($_REQUEST["file_ref"] . "</span>: " . $key . "." . (!$retry?"":" <span class='retrying'>Retrying</span> in <span class='retry_time'>" . $retry_interval . "</span>s.":"");
}
}
echo $outcome;
}
So I use an array with the keys set as the error msg, and if a key is set to false, that’s the step the process seemingly broke on. Depending on the given error, the process could retry, so there’s a retry variable set as well. If I could set this retry variable also in the if statement, I’d love it.
I was playing around w/doing this in a catch statement, and somehow moving the pointer through the array as the conditions proved true, and see where I could potentially do this:
switch(true)
case (set array key to condition)
set retry
break;
case (set array key to condition)
set retry
break;
case (set array key to condition)
set retry
break;
default
The problem with this though is that since these are steps, I want to progress past the step if it proves truth (meaning no “break”), but if it’s false, I want it to break and not try to test all the rest of the conditions. A nested loop would do that. One of these processes being an FTP login, the PHP actually gives a waiting/timeout period for the login attempt, which is a resource-heavy conditional, so I don’t want to go through all conditionals to test true/false.
Feedback appreciated.