Jump to content


Photo

custom error handling question


  • Please log in to reply
No replies to this topic

#1 makeshift_theory

makeshift_theory
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts

Posted 25 October 2006 - 07:02 PM

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?

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


<b>Emacs</b> it's great for the body.
<br><br>
<b>Trust the TechnoLust</b>

<b><u>Have a question check here:</u></b>
PHP Manual: http://www.php.net




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users