-
Notifications
You must be signed in to change notification settings - Fork 0
/
csv-txt-filestype.php
94 lines (80 loc) · 3.92 KB
/
csv-txt-filestype.php
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
session_start();
// uploaded_messages
require_once '../data_handler.php';
$data_Obj = new data_processor();
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
// print_r($_FILES["file"]);
$data = fopen($_FILES['file']['tmp_name'], 'rb');
$file_type = $_FILES["file"]["type"];
$extension = strtolower(pathinfo($_FILES["file"]["name"],PATHINFO_EXTENSION));
if ($extension != "txt" && $extension != "csv")
{
header('Location: ../schedule_broadcast.php?qw=only-text-file-required');
$_SESSION['notice_message'] = 'Only a text and scv files types are required!';
}
elseif ($file_type != 'text/plain' && $file_type != 'application/vnd.ms-excel')
{
header('Location: ../schedule_broadcast.php?qw=bad-file-type');
$_SESSION['notice_message'] = 'This type of file cannot be uploaded!';
}
else
{
if ($extension == "txt" && $file_type == 'text/plain')
{
while (($line = fgets($data)) !== false)
{
$content = explode(';', $line);
error_reporting(0);
$message = trim($content[0]);
$keyword = trim($content[1]);
$dateToSend = trim($content[2]);
$todays_date = date('Y-m-d');
$service_id = "";
//get service id for the given keyword.......................
foreach ($data_Obj->get_keyword_details_for_sms($keyword) as $key)
{
$service_id = $key['service'];
}
// sleep(1);
// do data insertion now..................
$uploaded = $data_Obj->_do_mass_content_upload($keyword, $service_id, $message, $dateToSend);
}
if ($uploaded) {
header('Location: ../schedule_broadcast.php?success=file-upload-suceeded');
$_SESSION['notice_message'] = 'TXT file content uploaded successfully!';
} else {
header('Location: ../schedule_broadcast.php?failed=file-upload-failed');
$_SESSION['notice_message'] = 'TXT file content upload failed!';
}
} elseif ($extension == "csv" && $file_type == 'application/vnd.ms-excel')
{
$detail = fopen($_FILES['file']['tmp_name'], 'r');
while (($content = fgetcsv($detail, 1000, ',')) !== false)
{
error_reporting(0);
$message = trim($content[0]);
$keyword = trim($content[1]);
$dateToSend = trim($content[2]);
$todays_date = date('Y-m-d');
$service_id = "";
//get service id for the given keyword.......................
foreach ($data_Obj->get_keyword_details_for_sms($keyword) as $key)
{
$service_id = $key['service'];
}
// sleep(1);
// do data insertion now..................
$uploaded = $data_Obj->_do_mass_content_upload($keyword, $message, $dateToSend);
}
if ($uploaded) {
header('Location: ../schedule_broadcast.php?success=file-upload-suceeded');
$_SESSION['notice_message'] = 'CSV file content uploaded successfully!';
} else {
header('Location: ../schedule_broadcast.php?failed=file-upload-failed');
$_SESSION['notice_message'] = 'CSV file content upload failed!';
}
}
}
}