forked from WP-API/WP-API
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupload.php
More file actions
103 lines (75 loc) · 2.91 KB
/
upload.php
File metadata and controls
103 lines (75 loc) · 2.91 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
require_once("../../../wp-load.php");
require_once './vendor/autoload.php';
$config = new \Flow\Config();
$file = new \Flow\File($config);
$request = new \Flow\Request($config);
if ($_SERVER['REQUEST_METHOD'] === 'GET' ) {
$chunkDir = './app/.tmp' . DIRECTORY_SEPARATOR . $file->getIdentifier();
if (!file_exists($chunkDir)) {
mkdir($chunkDir);
chmod($chunkDir, 0777);
}
$config->setTempDir($chunkDir);
$file = new \Flow\File($config);
print_r($file); echo ' ::: get request';
if ($file->checkChunk()) {
header("HTTP/1.1 200 Ok");
} else {
echo ' ::: chunk checked okay, there was no content';
header("HTTP/1.1 204 No Content");
return ;
}
} else {
echo ' ::: post request ::: > '. $file->getIdentifier() .' < ::: ';
$chunkDir = './app/.tmp' . DIRECTORY_SEPARATOR . $file->getIdentifier();
$config->setTempDir($chunkDir);
$file = new \Flow\File($config);
if ($file->validateChunk()) {
echo ' ::: chunk validate okay ::: ';
$file->saveChunk();
print_r($_REQUEST); echo ' ::: saving chunk ::: ';
// saving right away for now...
echo ' ::: we are updating so skip this check, save channel image right away ::: ';
saveChannelImage($file->getIdentifier());
} else {
// error, invalid chunk upload request, retry
echo ' ::: chunk didn\'t validate okay';
// header("HTTP/1.1 400 Bad Request");
return ;
}
// die();
}
if (isset($_REQUEST['updateChannel'])) {
print_r($_REQUEST);
}
echo ' ::: end';
function saveChannelImage($identifier) {
global $wpdb;
echo $identifier, ' ? ::: ';
$config = new \Flow\Config();
$chunkDir = './app/.tmp' . DIRECTORY_SEPARATOR . $identifier;
$config->setTempDir($chunkDir);
$file = new \Flow\File($config);
if ($file->validateFile() ) {
$channelImgDir = '../../uploads/channels';
// echo ' ', $channelImgDir;
if (!file_exists($channelImgDir)) {
mkdir($channelImgDir);
chmod($channelImgDir, 0777);
// File upload was completed
echo 'created uploads/channels folder';
}
$request = new \Flow\Request();
print_r($request); echo ' ::: request in saveChannelImage ::: ', $request->getFileName();
if (\Flow\Basic::save($channelImgDir . DIRECTORY_SEPARATOR . $request->getFileName(), $config, $request)) {
echo "Hurray, file was saved in " .$channelImgDir . DIRECTORY_SEPARATOR . $request->getFileName();
echo 'update this channel! ('.$_REQUEST['channel'].')';
if ( ! add_term_meta( $_REQUEST['channel'], 'cutv_channel_img', $request->getFileName(), true ) ) {
update_term_meta($_REQUEST['channel'], 'cutv_channel_img', $request->getFileName());
}
}
} else {
// This is not a final chunk, continue to upload
}
}