forked from WWBN/AVideo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport.json.php
75 lines (61 loc) · 2.13 KB
/
import.json.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
<?php
global $global, $config;
if (!isset($global['systemRootPath'])) {
require_once '../videos/configuration.php';
}
header('Content-Type: application/json');
if (!User::canUpload() || !empty($advancedCustom->doNotShowImportMP4Button)) {
return false;
}
if (!preg_match("/.*\\.mp4$/i", $_POST['fileURI'])) {
return false;
}
$obj = new stdClass();
$obj->error = true;
$obj->fileURI = pathinfo($_POST['fileURI']);
//get description
$filename = $obj->fileURI['dirname'] . DIRECTORY_SEPARATOR . $obj->fileURI['filename'];
$extensions = ['txt', 'html', 'htm'];
$length = intval($_POST['length']);
if (empty($length) || $length>100) {
$length = 100;
}
foreach ($extensions as $value) {
$_POST['description'] = '';
$_POST['title'] = '';
if (file_exists("{$filename}.{$value}")) {
$html = file_get_contents("{$filename}.{$value}");
$breaks = ["<br />","<br>","<br/>"];
$html = str_ireplace($breaks, "\r\n", $html);
$_POST['description'] = $html;
$cleanHTML = strip_tags($html);
$_POST['title'] = substr($cleanHTML, 0, $length);
break;
}
}
$tmpDir = sys_get_temp_dir();
$tmpFileName = $tmpDir.DIRECTORY_SEPARATOR.$obj->fileURI['filename'];
$source = $obj->fileURI['dirname'] . DIRECTORY_SEPARATOR . $obj->fileURI['basename'];
if (!copy($source, $tmpFileName)) {
$obj->msg = "failed to copy $filename...\n";
die(json_encode($obj));
}
if (!empty($_POST['delete']) && $_POST['delete'] !== 'false') {
if (is_writable($source)) {
unlink($source);
foreach ($extensions as $value) {
if (file_exists("{$filename}.{$value}")) {
unlink("{$filename}.{$value}");
}
}
} else {
$obj->msg = "Could not delete $source...\n";
}
}
$_FILES['upl']['error'] = 0;
$_FILES['upl']['name'] = $obj->fileURI['basename'];
$_FILES['upl']['tmp_name'] = $tmpFileName;
$_FILES['upl']['type'] = 'video/mp4';
$_FILES['upl']['size'] = filesize($tmpFileName);
require_once $global['systemRootPath'] . 'view/mini-upload-form/upload.php';
echo json_encode($obj);