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