<?php
include_once("includes/connect.php");
?>
<script language="JavaScript">
<!--
function refreshParent() {
window.opener.location.href = window.opener.location.href;
if (window.opener.progressWindow)
{
window.opener.progressWindow.close()
}
window.close();
}
//-->
</script>
<?php
if($_POST){
/*------------------| Upload the file in Server |------------------*/
//print_r($_FILES);
$max_photo_size=50000;
$upload_required=true;
$upload_dir='mails/';
$err_msg=false;
do{
if(!isset($_FILES['book_image'])){
$err_msg="The form was not sent in completely.";
break;
}else{
$book_image=$_FILES['book_image'];
}
switch ($book_image['error']){
case UPLOAD_ERR_INI_SIZE:
$err_msg = 'The size of the image is too large.';
break 2;
case UPLOAD_ERR_PARTIAL:
$err_msg = 'An error occured while uploading the files.';
break 2;
case UPLOAD_ERR_NO_FILE:
$err_msg = 'You did not select a file to upload.';
break 2;
case UPLOAD_ERR_OK:
if($book_image['size'] > $max_photo_size){
$err_msg = 'The size of the file is too large.';
}
break 2;
default:
$err_msg = 'An unknown error occured.';
break 2;
}
if(!in_array($book_image['type'], array('text/plain'))){
$err_msg = 'You need to upload a text file';
break;
}
}while (0);
if(!$err_msg){
if(!move_uploaded_file($book_image['tmp_name'], $upload_dir. $book_image['name'])){
$err_msg='Error moving file in destination';
}
}
/*---------------| Uploading file is over |---------------------*/
/*---------------| Reading file data |----------------------*/
$myFile = $upload_dir.$book_image['name'];
//$myFile = 'mails/example.txt';
//echo $myFile;
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
echo $theData;
echo "<hr/>";
fclose($fh);
/*---------------| Counting the number of results |----------------*/
$countSpace = substr_count($theData, "\n");
echo $countSpace;
$emailArray=explode("\n", $theData);
$rid = mysql_real_escape_string($_REQUEST['txt_rid']);
$wb='Y';
/*----------------| Inserting the records in the db |---------------*/
for($i=0; $i<=$countSpace; $i++){
$email = mysql_real_escape_string($emailArray[$i]);
/*-------| Save value in primary table |--------------------*/
$query0="SELECT id FROM mailaddr WHERE email like '%".$email."%'";
$query0_execute=mysql_query($query0) or die(mysql_error());
$query0_rows=mysql_num_rows($query0_execute);
if($query0_rows>=1){
$query0_result=mysql_fetch_assoc($query0_execute);
$id=$query0_result[id];
//echo $id;
}else{
$query1="INSERT INTO mailaddr (priority, email) VALUES('7','".$email."')";
echo $query1;
mysql_query($query1) or die('Insert Error 1');
}
/*-------| Get last record from primary table |------------*/
$query2="SELECT max(id) FROM mailaddr";
$query2_execute=mysql_query($query2) or die('error');
$query2_show=mysql_fetch_row($query2_execute);
/*-------| Blacklist/Whitelist Values |--------------------*/
if($query0_rows>=1){
$query3="INSERT INTO wblist (rid, sid, wb) VALUES('".$rid."', '".$id."','".$wb."')";
}else{
$query3="INSERT INTO wblist (rid, sid, wb) VALUES('".$rid."', '".$query2_show[0]."','".$wb."')";
}
mysql_query($query3) or die("Email already blacklisted or whitelisted.<br/><input type=\"button\" value=\"Close\" onclick=\"window.close();\">");
$query_insert="Data Successfully inserted";
}
unlink($myFile);
echo "<script>refreshParent();</script>";
}
?>
<body bgcolor="#B7C9E1">
<br/>
<?php
if($err_msg){
echo $err_msg;
}
?>
<form id="frmAddNewUser" enctype="multipart/form-data" method="post" action="import_whitelist.php">
<table border="0" cellspacing="0" cellpadding="0" width="300">
<tr>
<td width="33%" class="policyContent">File :</td>
<td width="67%" class="policyInput">
<input type="hidden" name="MAX_FILE_SIZE" value="16000"/>
<input type="file" name="book_image" style="border: #2D3191 2px solid;">
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td class="policyContent" align="center">
<input type="hidden" name="txt_hidval" id="txt_hidval" value="0"><input type="hidden" name="txt_rid" id="txt_rid" value="<?php echo $_REQUEST['rid'];?>"><input type="Submit" value="Save" class="button"></td>
</tr>
</table>
</form>
</body>
Monday, October 6, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment