Page 1 of 1

File Upload script + Duplicate Checking + help

Posted: Wed Mar 23, 2005 11:16 pm
by harsha
HI
ALL

I am writing a file upload script I am able to upload the file and add the file name to the list,
And it is now able to check the duplicates to some extent,
I have written the code for checking duplicates which works fine on certain conditions only.

Code: Select all

<?
if(isset($_POST['fileAttach']) AND isset($_POST['selFileList']))
  {
	if(is_array($_POST['selFileList']) AND (count($_POST['fileAttach']) > 0))
	  {
		$duplicate_file = array();
		foreach($_POST['selFileList'] as $uploadFileName)
		  {
			foreach(array_unique($_FILES['fUploader']['name']) as $file_name)
			  {
			    if(strcasecmp($uploadFileName, $file_name) == 0)
				  {
				     array_push($duplicate_file, $file_name);
				  }
			  }
		  }
	  }
  }
?>
<select name="selFileList[]" size="6" multiple class="FILE" id="selFileList"><?
if(isset($_POST['fileAttach']))
  { 
  	$upload_tmp_name = array_unique($_FILES['fUploader']['tmp_name']);
	foreach(array_unique($_FILES['fUploader']['name']) as $file_number => $file_name)
	 {
       $uploadedFileName = $file_name;
       $temporaryFileName = $upload_tmp_name[$file_number];
	   if(isset($duplicate_file) AND (count($duplicate_file) > 0))
		 {
			foreach($duplicate_file as $duplicate_name)
			  {
				if(!(strcasecmp($duplicate_name, $uploadedFileName) == 0))
				  {
					if(move_uploaded_file($temporaryFileName, $sg_usersFileUploadDir.$uploadedFileName))
					  {
						echo "<option value=\"{$uploadedFileName}\">".$uploadedFileName."</option>\n\n";      
					  }
				  }
			  }
		}
	   else 
		{
		   if(move_uploaded_file($temporaryFileName, $sg_usersFileUploadDir.$uploadedFileName))
			{
				echo "<option value=\"{$uploadedFileName}\">".$uploadedFileName."</option>\n\n";      
			}
		}
	 }//foreach;
	if(isset($_POST['selFileList']))
	 {
		foreach($_POST['selFileList'] as $file_key => $file_value)
		  {
			 echo "<option value=\"{$file_value}\">".$file_value."</option>\n\n";
		  }
	 }
  } //fileAttach;
else if(isset($_POST['toform2']) AND isset($_POST['selFileList']))
  {
	foreach($_POST['selFileList'] as $value) 
	  {
		echo "<option value=\"{$value}\">".$value."</option>\n\n";
	  }
  }      
else if(isset($_POST['btnRemove']) AND isset($_POST['selFileList']))
  {
	foreach($_POST['selFileList'] as $file_key => $file_value)
	  {
		echo "<option value=\"{$file_value}\">".$file_value."</option>\n\n";
	  }
  }
?>

Posted: Wed Mar 23, 2005 11:54 pm
by feyd
okay... and you want us to do or say what?

Posted: Thu Mar 24, 2005 1:19 am
by harsha
No
Please help me by Highlight the mistake that i have done in the script,

:D thank you

Posted: Thu Mar 24, 2005 7:40 am
by Chris Corbyn
You didn't say what the problem was? :?