-
Notifications
You must be signed in to change notification settings - Fork 0
/
newproductupload.php
184 lines (163 loc) · 6.84 KB
/
newproductupload.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<!DOCTYPE html>
<html lang="en">
<head>
<?php
include('general.php');
include('productuploadcode.php');
putLinks();
/* session_start();
if( strcasecmp($_SERVER['REQUEST_METHOD'],"POST") === 0) {
$_SESSION['postdata'] = $_POST;
header("Location: ".$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']);
exit;
}
if( isset($_SESSION['postdata'])) {
$_POST = $_SESSION['postdata'];
unset($_SESSION['postdata']);
} */
?>
<title>Chromis PHP - Categories</title>
</head>
<body>
<header class="site__header island">
<div class="wrap">
<span id="animationSandbox" style="display: block;" class="tada animated">
<h1 class="site__title mega text-center">New Product Upload</h1>
</span>
</div>
</header>
<form action="newproductupload.php" method="POST" enctype="multipart/form-data">
<div class="row">
<div class="form-group">
<div class="col-lg-3"></div>
<div class="col-lg-6 text-right">
<a class="glyphicon glyphicon-home text-info" style="font-size:30px;" href="/chromisphp/"></a>
</div>
<div class="col-lg-3"></div>
</div> <!-- form-group -->
</div> <!-- row close -->
<div class="row">
<div class="form-group">
<div class="col-lg-3"></div>
<div class="col-lg-6 text-right">
<div class="table-bordered"> <!-- just for the frame -->
<input class="btn btn-warning btn-block text-right" type="file" name="fileToUpload" id="fileToUpload">
<span class='label label-danger center-block' id="upload-file-info"></span>
</div> <!-- table bordered closed -->
</div> <!-- column close -->
<div class="col-lg-3"></div>
</div> <!-- form-group -->
</div> <!-- row close -->
<div class="row">
<div class="form-group">
<div class="col-lg-3"></div>
<div class="col-lg-6 text-right">
<div> <!-- just for the frame -->
<button type="submit" class="btn btn-success" id="btnUpload" name="upload" onclick="return confirm('Do you want to upload?')">Upload</button>
<span><button type="submit" class="btn btn-info" id="btnPreview" name="preview" onclick="return confirm('Do you want to preview?')">Preview</button></span>
</div> <!-- just frame close table bordered closed -->
</div> <!-- column close -->
<div class="col-lg-3"></div>
</div> <!-- form-group -->
</div> <!-- row close -->
</form>
<br />
<div class="row"> <!-- output row open -->
<div class="col-lg-12"> <!-- output 12 column open -->
</div>
</div>
<div class="row"> <!-- output row open -->
<div class="col-lg-12"> <!-- output 12 column open -->
<?php
if (isset($_POST['upload']))
{
// $message = "Upload Pressed";
// echo "<script type='text/javascript'>alert('$message');</script>";
$target_dir = "uploads/";
$uniquefile =
$target_file = $target_dir . getUniqueDateTime() . '_' . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$uploadFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($uploadFileType != "csv")
{
echo "Sorry, only csv file allowed.";
$uploadOk = 0;
}
if ($uploadOk == 0)
{
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
//echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
if (csvupload($target_file))
{
$message = "Upload completed!";
echo "<script type='text/javascript'>alert('$message');</script>";
}
} else {
echo "Sorry, there was an error uploading your file.";
}
}
}
if (isset($_POST['preview']))
{
$target_dir = "uploads/";
$uniquefile =
$target_file = $target_dir . getUniqueDateTime() . '_' . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$uploadFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($uploadFileType != "csv")
{
echo "Sorry, only csv file allowed.";
$uploadOk = 0;
}
if ($uploadOk == 0)
{
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
//echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
if(csvPreview($target_file))
{
$message = "Preview completed!";
echo "<script type='text/javascript'>alert('$message');</script>";
}
} else {
echo "Sorry, there was an error uploading your file.";
}
}
}
?>
</div> <!-- output 12 column space close -->
</div> <!-- output row close -->
<?php
//include('general.php');
putScripts();
//stickfooter();
?>
</body>
</html>