-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.php
executable file
·55 lines (42 loc) · 1.16 KB
/
upload.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
<?php
/**
* Template Name: Upload (backend)
* Description: Uploads an image to a chapter
*/
?>
<?php
include_once 'lib/Chapter.php';
include_once 'lib/Comic.php';
include_once 'lib/Page.php';
// Only logged in users have access to POST and DELETE
if (!current_user_can('upload_files')) {
return;
}
$requestMethod = $_SERVER['REQUEST_METHOD'];
if ($requestMethod == 'POST') {
$data = $_POST;
$resourceType = $data['resource'];
if ($resourceType == 'delete_page') {
$page = Page::findById($data['id']);
if (!$page) {
return;
}
$page->delete();
}
if ($resourceType == 'page') {
$resource = new Page($data['page_name'], $data['page_number'], $data['chapter_id'], $_FILES['page_image']['name']);
// Upload the image
$filePath = $_FILES['page_image']['tmp_name'];
$newFilePath = ABSPATH . 'wp-content/uploads/live/' . $_FILES['page_image']['name'];
rename($filePath, $newFilePath);
chmod($newFilePath, 0644);
}
if ($resourceType == 'chapter') {
$resource = new Chapter($data['chapter_number'], $data['chapter_title']);
}
if ($resource) {
$resource->save();
}
}
header("Location: " . $_SERVER['HTTP_REFERER']);
return '';