-
Notifications
You must be signed in to change notification settings - Fork 11
/
rawupload.php
49 lines (47 loc) · 1.28 KB
/
rawupload.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
<?php
require_once('./config.class.php');
$allowed = array('gif', 'png', 'jpg', 'jpeg', 'mp4', 'mov');
if ( isset($_FILES['raw_upload']) ) {
$ext = pathinfo($_FILES['raw_upload']['name'], PATHINFO_EXTENSION);
if ($_FILES['raw_upload']['error']) {
// do nothing
// var_dump($_FILES['raw_upload']);
} else if (!in_array($ext, $allowed)) {
echo 'Unsupported filetype';
} else {
$filename = date('Ymd_His_') . rand(0, 100000);
$fullpath = Config::raw_uploads_folder . '/' . $filename;
move_uploaded_file($_FILES['raw_upload']['tmp_name'], $fullpath);
echo $filename;
}
} else {
?><!DOCTYPE html>
<html>
<head>
<title>Uploader</title>
<script language="javascript" src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script language="javascript">
$(document).ready(function(){
$('#the-button').click(function(){
var formData = new FormData($('form')[0]);
$.ajax({
url: '',
type: 'POST',
success: function(e){ console.log(e); },
data: formData,
cache: false,
contentType: false,
processData: false,
});
});
});
</script>
</head>
<body>
<form enctype="multipart/form-data">
<input type="file" name="raw_upload" id="file-upload" />
<button type="button" id="the-button">Submit!</button>
</form>
</body>
</html><?php
}