-
Notifications
You must be signed in to change notification settings - Fork 0
/
mobileupload.php
117 lines (95 loc) · 4.57 KB
/
mobileupload.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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
require_once("../../config.php");
require_once("lib.php");
require_once("SimpleImage.php");
require_once("getid3/getid3.php");
$id = optional_param('id', 0, PARAM_INT);
$cid = optional_param('cid', 0, PARAM_INT);
$uid = optional_param('uid', 0, PARAM_INT);
$time = optional_param('time', NULL, PARAM_CLEAN);
$type = optional_param('type', NULL, PARAM_CLEAN);
$slideimages = optional_param('slideimages', NULL, PARAM_CLEAN);
$fname = optional_param('fname', NULL, PARAM_CLEAN);
$userdata = $DB->get_record("user", array("id"=>$uid));
$data = $DB->get_record_sql("SELECT * FROM {mediaboard_files} WHERE userid=? AND instance=? ORDER BY id DESC", array($uid, $id));
$aid = $data->id;
$unicalid = substr(time(), 2).rand(0,9);
$contextmodule = get_context_instance(CONTEXT_MODULE, $data->instance);
$context = get_context_instance(CONTEXT_USER, $uid);
$fs = get_file_storage();
list(,$sid) = explode("_", $fname);
if ($type == 'image') {
$file = $CFG->dataroot."/tmp.jpg";
if (move_uploaded_file($_FILES['media']['tmp_name'], $file)) {
//-------Resize images----------//--500x280
@$image=imagecreatefromjpeg($file);
$w=getimagesize($file);
$width = 500;
$height = 370;
if ($w[0] < $w[1]) {
$imagef = new SimpleImage();
$imagef->load($file);
$imagef->resizeToHeight($height);
$imagef->save($file);
$w=getimagesize($file);
if($w[0] > $width) {
$imagef->resizeToWidth($width);
$imagef->save($file);
}
} else if ($w[0] >= $w[1]) {
$imagef = new SimpleImage();
$imagef->load($file);
$imagef->resizeToWidth($width);
$imagef->save($file);
$w=getimagesize($file);
if($w[1] > $height) {
$imagef->resizeToHeight($height);
$imagef->save($file);
}
}
$file_record = new stdClass;
$file_record->component = 'mod_mediaboard';
$file_record->contextid = $contextmodule->id;
$file_record->userid = $uid;
$file_record->filearea = 'private';
$file_record->filepath = "/";
$file_record->itemid = $unicalid;
$file_record->license = $CFG->sitedefaultlicense;
$file_record->author = fullname($userdata);
$file_record->source = '';
$file_record->filename = "slide_image.jpg";
$itemid = $fs->create_file_from_pathname($file_record, $file);
unlink($file);
$DB->set_field("mediaboard_items", "image".$sid, $itemid->get_id(), array("fileid"=>$aid));
}
} else if ($type == 'audio') {
$file = $CFG->dataroot."/tmp.m4a";
if (move_uploaded_file($_FILES['media']['tmp_name'], $file)) {
$file_record = new stdClass;
$file_record->component = 'mod_mediaboard';
$file_record->contextid = $contextmodule->id;
$file_record->userid = $uid;
$file_record->filearea = 'private';
$file_record->filepath = "/";
$file_record->itemid = $unicalid;
$file_record->license = $CFG->sitedefaultlicense;
$file_record->author = fullname($userdata);
$file_record->source = '';
$file_record->filename = "slide_audio.m4a";
$itemid = $fs->create_file_from_pathname($file_record, $file);
$getID3 = new getID3;
$getID3->setOption(array('encoding' => 'UTF-8'));
$ThisFileInfo = $getID3->analyze($file);
unlink($CFG->dataroot."/tmp.m4a");
$DB->set_field("mediaboard_items", "audio".$sid, $itemid->get_id(), array("fileid"=>$aid));
$DB->set_field("mediaboard_items", "duration".$sid, @round((float)$ThisFileInfo['playtime_seconds'] * 1000), array("fileid"=>$aid));
$DB->set_field("mediaboard_items", "combinateaudio", 0, array("fileid"=>$aid));
$add = new stdClass;
$add->itemid = $itemid->get_id();
$add->type = 'audio/mp3';
$add->status = 'open';
$add->name = md5($CFG->wwwroot.'_'.time().'_'.$sid);
$add->time = time();
$DB->insert_record("mediaboard_process", $add);
}
}