-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert.php
More file actions
86 lines (67 loc) · 2.05 KB
/
insert.php
File metadata and controls
86 lines (67 loc) · 2.05 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
76
77
78
79
80
81
82
83
84
85
86
<?php
$data = $_POST;
//FIELD VALIDATION
$errors = [];
foreach (['title', 'username', 'veri','texts', 'atype'] as $field) {
if (empty($data[$field])) {
$errors[] = sprintf('The %s is a required field.', $field);
}
}
if (!empty($errors)) {
echo implode('<br />', $errors);
exit;
}
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["filename"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
//check if image file is actual image
if(isset($_POST["submit"])){
$check = getimagesize($_FILES["filename"]["tmp_name"]);
if($check !== false){
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
}
else{
echo "File is not an image.";
$uploadOk = 0;
}
}
//DATABASE CONNECT
$host = 'localhost';
$database = 'joannaDB';
$user = 'joanna';
$pass = 'J0annaSeniorProject!';
$dsn = sprintf("mysql:host=%s;dbname=%s;", $host, $database);
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
];
try {
$pdo = new PDO($dsn, $user, $pass, $options);
} catch (\PDOException $e) {
throw new \PDOException($e->getMessage(), (int)$e->getCode());
}
//INSERT INTO ARTICLE
$statement = $pdo->prepare(
'INSERT INTO articles (article_title, author_username, author_verification, article_text_path, article_type) VALUES (:title, :username, :veri, :texts, :atype)'
);
$statement->execute([
'title' => $data['title'],
'username' => $data['username'],
'veri' => $data['veri'],
'texts' => $data['title'] . '.html',
'atype' => $data['atype']
]);
echo 'The article has been successfully saved.';
$fileName = $data['title'] . '.html';
$textFile = $_POST['texts'];
$myfile = fopen($textFile, "w");
fwrite($myfile, $textFile);
fclose($myfile);
$command = escapeshellcmd('python 3 /home/joannadir/repos/seniorproject/createPage.py');
$output = shell_exect($command);
echo $output;
$linkAddress = "." . $fileName;
echo "<a href'".$linkAddress."'>Link</a>";
?>