-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.php
60 lines (54 loc) · 1.94 KB
/
edit.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
<?php
require_once('modules/startup.php');
require('modules/classes.php');
require('modules/repository.php');
$link = startup();
$getTitle="Редактирование статьи";
$titleNew = '';
$contentNew = '';
$change = false;
$error = false;
$error_message = [];
$arr = ArticleRepo::load($link, $_GET['id']);
$title = $arr->getTitle();
$content = $arr->getContent();
if(!empty($_POST) && isset($_POST['titleNew']) && isset($_POST['contentNew'])) {
$titleNew = trim($_POST['titleNew']);
$contentNew = trim($_POST['contentNew']);
if(isset($_FILES['image'])) {
if ($_FILES['image']['name'] != '') {
$arrtype = array('image/jpeg', 'image/gif', 'image/png');
if (in_array($_FILES['image']['type'], $arrtype) && $_FILES['image']['size'] < 1000000) {
if (!is_dir("img")) {
mkdir("img");
}
if (ImageUpload::upload($link, $_FILES['image'])) {
$name = $_FILES['image']['name'];
$name = " '$name' ";
$add = ImageRepo::add($link, $name, $_GET['id']);
$change = true;
}
} else {
$error = true;
$error_message[] = 'Файл должен быть формата .jpg, .png или .gif и размером меньше 1Mb';
}
}
}
if(!empty($titleNew) && !empty($contentNew)) {
if(ArticleRepo::edit($link, $_GET['id'], $_POST['titleNew'], $_POST['contentNew'])) {
$title = $titleNew;
$content = $contentNew;
$change = true;
}
} else {
$error = true;
$error_message[] = "Заполните все поля!";
}
}
if($change && !$error) {
header("location: article.php?id=".$_GET['id']);
}
header('Content-type: text/html; charset=utf-8');
include('views/header.php');
include('views/v_edit.php');
include('views/footer.php');