]>
Commit | Line | Data |
---|---|---|
a7f8ccab | 1 | <?php |
2f98035a PAB |
2 | //Loading configuration file |
3 | require_once "config.php"; | |
4 | ||
5 | //Saving the file on the server | |
b5352106 | 6 | function save_file ($file, $name, $arg, $type){ |
9e80f78f GJ |
7 | //Generate name depending on arg |
8 | switch($arg){ | |
9 | case 'random': | |
10 | $ext = pathinfo($file.$name, PATHINFO_EXTENSION); | |
e7112627 | 11 | $ext = strtolower($ext); |
2f98035a PAB |
12 | if(in_array($ext, unserialize(CONFIG_BLOCKED_EXTENSIONS))){ |
13 | if($type==='normal'){ | |
14 | include_once(CONFIG_ROOT_PATH.'error_meow.php'); | |
b5352106 | 15 | exit(0); |
2f98035a PAB |
16 | }else{ |
17 | exit('File type not allowed.'); | |
18 | } | |
19 | } | |
9e80f78f | 20 | $file_name = gen_name('random', $ext); |
2f98035a PAB |
21 | while(file_exists(CONFIG_FILES_PATH.$file_name)){ |
22 | $file_name = gen_name('random', $ext); | |
9e80f78f GJ |
23 | } |
24 | break; | |
25 | case 'custom_original': | |
a70886b3 | 26 | $name = stripslashes(str_replace('/', '', $name)); |
9e80f78f | 27 | $name = strip_tags(preg_replace('/\s+/', '', $name)); |
e7112627 GJ |
28 | $file_name = gen_name('custom_original', $name); |
29 | $ext = pathinfo($file_name, PATHINFO_EXTENSION); | |
30 | $ext = strtolower($ext); | |
2f98035a PAB |
31 | if(in_array($ext, unserialize(CONFIG_BLOCKED_EXTENSIONS))){ |
32 | if($type==='normal'){ | |
33 | include_once(CONFIG_ROOT_PATH.'error_meow.php'); | |
34 | exit(0); | |
35 | }else{ | |
36 | exit('File type not allowed.'); | |
37 | } | |
b5352106 | 38 | } |
2f98035a | 39 | while(file_exists(CONFIG_FILES_PATH.$file_name)){ |
9e80f78f GJ |
40 | $file_name = gen_name('custom_original', $name); |
41 | } | |
42 | break; | |
43 | } | |
44 | //Move the file to the above location with said filename | |
2f98035a | 45 | move_uploaded_file($file,CONFIG_FILES_PATH.$file_name); |
2a13cb35 GJ |
46 | //Check if html or plain text should be returned |
47 | if($type==='tool'){ | |
48 | //Return url+filename to the user (plain text) | |
2f98035a | 49 | echo CONFIG_ROOT_URL.'/files/'.urlencode($file_name); |
2a13cb35 GJ |
50 | exit(0); |
51 | }elseif($type==='normal'){ | |
52 | //Return url+filename to the user (HTML) | |
53 | $n=urlencode($file_name); | |
2f98035a | 54 | include_once(CONFIG_ROOT_PATH.'upload-done.php'); |
2a13cb35 GJ |
55 | exit(0); |
56 | } | |
9e80f78f | 57 | } |
2f98035a PAB |
58 | |
59 | #Generate a random name for the uploaded file | |
9e80f78f | 60 | function gen_name($arg, $in){ |
2f98035a | 61 | $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; |
9e80f78f | 62 | $name = ''; |
2f98035a PAB |
63 | for ($i = 0; $i < CONFIG_RANDOM_LENGTH; $i++) { |
64 | $name .= $chars[mt_rand(0, 60)]; | |
9e80f78f GJ |
65 | } |
66 | switch($arg){ | |
67 | case 'random': | |
68 | return $name.'.'.$in; | |
69 | break; | |
70 | case 'custom_original': | |
71 | return $name.'_'.$in; | |
72 | break; | |
73 | } | |
74 | } |