forked from WWBN/AVideo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuploadArticleImage.php
51 lines (48 loc) · 1.98 KB
/
uploadArticleImage.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
<?php
global $global, $config;
if (!isset($global['systemRootPath'])) {
require_once '../videos/configuration.php';
}
require_once $global['systemRootPath'] . 'objects/video.php';
if(empty($_GET['video_id']) && !empty($_POST['videos_id'])){
$_GET['video_id'] = $_POST['videos_id'];
}
$obj = new stdClass();
$obj->error = true;
if (!Video::canEdit($_GET['video_id'])) {
$obj->msg = 'You cant edit this file';
die(json_encode($obj));
}
header('Content-Type: application/json');
// A list of permitted file extensions
$allowed = array('jpg', 'gif', 'png');
if (isset($_FILES['file_data']) && $_FILES['file_data']['error'] == 0) {
$extension = pathinfo($_FILES['file_data']['name'], PATHINFO_EXTENSION);
if (!in_array(strtolower($extension), $allowed)) {
$obj->msg = "File extension error [{$_FILES['file_data']['name']}], we allow only (" . implode(",", $allowed) . ")";
die(json_encode($obj));
}
//var_dump($extension, $type);exit;
$video = new Video("", "", $_GET['video_id']);
if (!empty($video)) {
$dir = "{$global['systemRootPath']}videos/articleImages/" . $video->getFilename()."/";
$name = uniqid();
if(!is_dir($dir)){
mkdir($dir, 0777, true);
}
$destination = $dir . $name.".".strtolower($extension);
error_log("Try to move " . $destination . " \n " . print_r($video, true));
if (!move_uploaded_file($_FILES['file_data']['tmp_name'], $destination)) {
$obj->msg = "Error on move_file_uploaded_file(" . $_FILES['file_data']['tmp_name'] . ", " . $destination;
die(json_encode($obj));
}
$obj->url = "{$global['webSiteRootURL']}videos/articleImages/" . $video->getFilename()."/{$name}.".strtolower($extension);
$obj->error = false;
} else {
$obj->msg = "Video Not found";
die(json_encode($obj));
}
}
$obj->msg = "\$_FILES Error";
$obj->FILES = $_FILES;
die(json_encode($obj));