-
Notifications
You must be signed in to change notification settings - Fork 0
/
post_file.php
63 lines (40 loc) · 1.37 KB
/
post_file.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
<?php
include 'function.php';
// If you want to ignore the uploaded files,
// set $demo_mode to true;
// $demo_mode = false;
// $upload_dir = 'uploads/';
// $allowed_ext = array('jpg','jpeg','png','gif');
if(strtolower($_SERVER['REQUEST_METHOD']) != 'post'){
exit_status('Error! Wrong HTTP method!');
}
Files::add();
// if(array_key_exists('pic',$_FILES) && $_FILES['pic']['error'] == 0 ){
// $pic = $_FILES['pic'];
// if(!in_array(get_extension($pic['name']),$allowed_ext)){
// exit_status('Only '.implode(',',$allowed_ext).' files are allowed!');
// }
// if($demo_mode){
// // File uploads are ignored. We only log them.
// $line = implode(' ', array( date('r'), $_SERVER['REMOTE_ADDR'], $pic['size'], $pic['name']));
// file_put_contents('log.txt', $line.PHP_EOL, FILE_APPEND);
// exit_status('Uploads are ignored in demo mode.');
// }
// // Move the uploaded file from the temporary
// // directory to the uploads folder:
// if(move_uploaded_file($pic['tmp_name'], $upload_dir.$pic['name'])){
// exit_status('File was uploaded successfuly!');
// }
// }
// exit_status('Something went wrong with your upload!');
// Helper functions
function exit_status($str){
echo json_encode(array('status'=>$str));
exit;
}
function get_extension($file_name){
$ext = explode('.', $file_name);
$ext = array_pop($ext);
return strtolower($ext);
}
?>