-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.php
More file actions
75 lines (61 loc) · 4.54 KB
/
upload.php
File metadata and controls
75 lines (61 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
// connect database file
require_once('db_conn.php');
if(isset($_POST['importSubmit'])){
// Allowed mime types
$csvMimes = array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain');
// Validate whether selected file is a CSV file
if(!empty($_FILES['file']['name']) && in_array($_FILES['file']['type'], $csvMimes)){
// If the file is uploaded
if(is_uploaded_file($_FILES['file']['tmp_name'])){
// Open uploaded CSV file with read-only mode
$csvFile = fopen($_FILES['file']['tmp_name'], 'r');
//print_r($csvFile);exit();
// Skip the first line
fgetcsv($csvFile); // id
//print_r(fgetcsv($csvFile));exit();
// Parse data from CSV file line by line
while(($line = fgetcsv($csvFile ,1000, ",")) != FALSE){
// Get row data
$first_name = $line[0];
$email = $line[1];
$contact_no = $line[2];
$status = $line[3];
//exit();
// Check whether member already exists in the database with the same email
$prevQuery = "SELECT id FROM users_data WHERE email = '".$line[1]."'";
$prevResult = $conn->query($prevQuery);
if($prevResult->num_rows > 0){
// Update member data in the database
$conn->query("UPDATE users_data SET first_name = '".$first_name."', contact_no = '".$contact_no."',status = '".$status."' WHERE email = '".$email."'");
}else{
$sql = "INSERT INTO users_data (first_name, email, contact_no,status)
VALUES ('$first_name', '$email','$contact_no','$status');";
$result = $conn->query($sql);
//print_r($result);exit();
if(stristr($email, '@gmail.com') !== false){
$sql = "INSERT INTO gmail_tbl (gmail_email) VALUES ('$email')";
$conn->query($sql);
}elseif(stristr($email, '@yahoo.com')!== false){
$sql = "INSERT INTO yahoo_tbl (yahoo_email)
VALUES ('$email')";
$conn->query($sql);
}else{
$sql = "INSERT INTO other_tbl (other_email)
VALUES ('$email')";
$conn->query($sql);
}
}
}
// Close opened CSV file
fclose($csvFile);
$qstring = '?status=succ';
}else{
$qstring = '?status=err';
}
}else{
$qstring = '?status=invalid_file';
}
}
// Redirect to the listing page
header("Location: index.php".$qstring);