2 //Loading configuration file
3 require_once "config.php";
5 //Saving the file on the server
6 function save_file ($file, $name, $arg, $type){
7 //Generate name depending on arg
10 $ext = pathinfo($file.$name, PATHINFO_EXTENSION
);
11 $ext = strtolower($ext);
12 verify_extension($ext, $type);
13 $file_name = gen_name('random', $ext);
14 while(file_exists(CONFIG_FILES_PATH
.$file_name)){
15 $file_name = gen_name('random', $ext);
18 case 'custom_original':
19 $name = stripslashes(str_replace('/', '', $name));
20 $name = strip_tags(preg_replace('/\s+/', '', $name));
21 $file_name = gen_name('custom_original', $name);
22 $ext = pathinfo($file_name, PATHINFO_EXTENSION
);
23 $ext = strtolower($ext);
24 verify_extension($ext, $type);
25 while(file_exists(CONFIG_FILES_PATH
.$file_name)){
26 $file_name = gen_name('custom_original', $name);
30 //Move the file to the above location with said filename
31 move_uploaded_file($file,CONFIG_FILES_PATH
.$file_name);
32 //Check if html or plain text should be returned
34 //Return url+filename to the user (plain text)
35 if(CONFIG_SUBUPLOAD_URL_ENABLED
== "true"){
36 echo CONFIG_SUBUPLOAD_URL
.'/'.urlencode($file_name);
38 echo CONFIG_ROOT_URL
.'/files/'.urlencode($file_name);
41 }elseif($type==='normal'){
42 //Return url+filename to the user (HTML)
43 $n=urlencode($file_name);
44 include_once(CONFIG_ROOT_PATH
.'upload-done.php');
49 #Generate a random name for the uploaded file
50 function gen_name($arg, $in){
51 $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
53 for ($i = 0; $i < CONFIG_RANDOM_LENGTH
; $i++
) {
54 $name .= $chars[mt_rand(0, 60)];
60 case 'custom_original':
66 //Verify that the extension is allowed
67 function verify_extension($ext, $type){
68 if(CONFIG_EXTENSION_BLOCKING_MODE
== "WHITELIST") {
69 $allowed = in_array($ext, unserialize(CONFIG_ALLOWED_EXTENSIONS
));
71 $allowed = !in_array($ext, unserialize(CONFIG_BLOCKED_EXTENSIONS
));
76 include_once(CONFIG_ROOT_PATH
.'error_meow.php');
79 exit('File type not allowed.');