Jump to content

Archived

This topic is now archived and is closed to further replies.

makeshift_theory

custom error handling question

Recommended Posts

Ok here is the situation, I got my ftp script to work fine however I'm getting multiple success messages when the object is to receive one.  I realize it must be due to the loop but with the way it's coded I don't see the problem.  Maybe someone can shed some light?

[code]
function ftp_up($fromDir,$toDir,$chmod,$server,$user,$pass,$detail,$publish) {


$ftp_server = $server;
$ftp_user_name = $user;
$ftp_user_pass = $pass;
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if((!$conn_id) || (!$login_result)) {
echo "Could not Connect to the FTP Server";
exit();
}

  ftp_mkdir($conn_id, $toDir);
  ftp_chmod($conn_id,$chmod,$toDir);
  ftp_chdir($conn_id,$toDir); // First run this will be custom/

//echo ftp_pwd($conn_id); // Test to see the current ftp directory;

// Initialize Exception Array
$exceptions = array('.','..');


if ($handle = opendir($fromDir)) {
  while (false !== ($file = readdir($handle)))
  if (!in_array($file,$exceptions)) {
// handle slash exceptions
$from=str_replace('//','/',$fromDir.'/'.$file);
  if (is_file($from))
  { // If local file is a file handle here
    if(filemtime($from) >= $site_lastupdate && $publish == "L"){ // If file process was last update only!
  if(!ftp_put($conn_id,$file,$from,FTP_ASCII))
  $error[] = "Could not upload " . $toDir . "/" . $file . " correctly<br><br>";
  else
  $filesuccess[] = $file; // Get a list of successfully uploaded files
  if(!ftp_chmod($conn_id,$chmod,$file))
  $error[] = "Could not chmod " . $toDir . "/" . $file . " successfully.<br><br>";
} else { // Else Let's Upload All Dis Stuff!!!!
  if(!ftp_put($conn_id,$file,$from,FTP_ASCII))
  $error[] = "Could not upload " . $toDir . "/" . $file . " correctly<br><br>";
  if(!ftp_chmod($conn_id,$chmod,$file))
  $error[] = "Could not chmod " . $toDir . "/" . $file . " successfully.<br><br>";
}
  }
  if(is_dir($from))
  { // If local file is a folder handle here
  ftp_up($from,$toDir . "/" . $file,$chmod,$ftp_server,$ftp_user_name,$ftp_user_pass,$detail="1",$publish);
  }


 
  } // End Exception IF

  closedir($handle);
} else
$error[] = "Cannot Find Source Folder!"; // End Directory Handling

if($detail) { // If Error Detail Is Turned On
if($error)
foreach ($error as $err)
echo "<font color=red><b>" . $err . "</b></font>";
}

if($publish == "L") // If Last Updated is Turned on Print List of Files Uploaded
foreach ($filesuccess as $file)
echo "font color=navy><b>Uploaded " . $file . " successfully!<br>";

if(!$error) {
echo "<center><font color=navy><b>File Structure Uploaded Successfully.</b></font></center><br><br>";

}
// Stop Script Execution


} // End Function

[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.