-
Notifications
You must be signed in to change notification settings - Fork 0
/
updatingMedia.php
76 lines (51 loc) · 1.88 KB
/
updatingMedia.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
76
<?php
session_start();
require_once 'Buisness/dbConfig.php';
require_once 'Buisness/Media.cls.php';
$condition = $_FILES["media"]["tmp_name"];
$mediaTypes = array(0 => '.mp4','.webm','.ogg', 1 => '.mp3','.wav','.ogg', 2=> '.gif', '.jpg', '.png', '.svg');
$oldMedia = new Media();
$oldMedia->setId($_POST["id"]);
$oldMedia = $oldMedia->findById($connectionId);
if($condition != "") {
$uploadError = $_FILES["media"]["error"];
$file = $_FILES["media"]["tmp_name"];
$type = '.'.pathinfo($_FILES["media"]['name'],PATHINFO_EXTENSION);
$flag=false;
foreach ($mediaTypes as $key => $val){
if ($type == $val){
$flag=true;
}
}
if ($flag == false){
header('Location: updateMedia.php?id='.$oldMedia->getId().'&flag=false');
return;
}
}
$name = $_POST["mediaName"];
$contentId = $_POST["content"];
if ($condition != ""){
if (!is_uploaded_file($file)){echo "Image Upload Failed error // " .$uploadError; return;}
$path = "Media/".$_SESSION["id"]."/";
if (!is_dir($path)){mkdir($path, 0777, true);}
$newName = md5(uniqid(rand(), true));
$newFullPath = $path.$newName.$type;
move_uploaded_file($file, $newFullPath);
if(!unlink($oldMedia->getPath())){ echo "cannot delete physical file"; return;}
}
$media = new Media();
$media->setId($_POST["id"]);
$media->setName($name);
$media->setContentId($contentId);
if($condition != ""){
$media->setPath($newFullPath);
$media->setType($type);
}
if($oldMedia->getName() != $media->getName()){$media->updateName($connectionId);}
if($oldMedia->getContentId() != $media->getContentId()){$media->updateContentId($connectionId);}
if($condition != ""){
$media->updatePath($connectionId);
$media->updateType($connectionId);
}
header('Location: courseManagement.php');
?>