]> jfr.im git - uguu.git/blob - includes/core.php
320c21c0f9eb11fe325375ddb83baeb191538a72
[uguu.git] / includes / core.php
1 <?php
2 function save_file ($file, $name, $arg, $type){
3 //Where to save
4 $path='/home/neku/www/files/';
5 $block = array('exe', 'scr', 'rar', 'zip', 'com', 'vbs', 'bat', 'cmd', 'html', 'htm', 'msi');
6 //Generate name depending on arg
7 switch($arg){
8 case 'random':
9 $ext = pathinfo($file.$name, PATHINFO_EXTENSION);
10 $ext = strtolower($ext);
11 if(in_array($ext, $block)){
12 if($type==='normal'){
13 include_once('error_meow.php');
14 exit(0);
15 }else{
16 exit('File type not allowed.');
17 }
18 }
19 $file_name = gen_name('random', $ext);
20 while(file_exists($path.$file_name)){
21 $file_name = gen_name('random', $ext);
22 }
23 break;
24 case 'custom_original':
25 $name = stripslashes(str_replace('/', '', $name));
26 $name = strip_tags(preg_replace('/\s+/', '', $name));
27 $file_name = gen_name('custom_original', $name);
28 $ext = pathinfo($file_name, PATHINFO_EXTENSION);
29 $ext = strtolower($ext);
30 if(in_array($ext, $block)){
31 if($type==='normal'){
32 include_once('error_meow.php');
33 exit(0);
34 }else{
35 exit('File type not allowed.');
36 }
37 }
38 while(file_exists($path.$file_name)){
39 $file_name = gen_name('custom_original', $name);
40 }
41 break;
42 }
43 //Move the file to the above location with said filename
44 move_uploaded_file($file,$path.$file_name);
45 //Check if html or plain text should be returned
46 if($type==='tool'){
47 //Return url+filename to the user (plain text)
48 echo 'http://a.uguu.se/'.urlencode($file_name);
49 exit(0);
50 }elseif($type==='normal'){
51 //Return url+filename to the user (HTML)
52 $n=urlencode($file_name);
53 include_once('/home/neku/www/page/public/upload-done.php');
54 exit(0);
55 }
56 }
57 function gen_name($arg, $in){
58 $chars = 'abcdefghijklmnopqrstuvwxyz';
59 $name = '';
60 for ($i = 0; $i < 6; $i++) {
61 $name .= $chars[mt_rand(0, 25)];
62 }
63 switch($arg){
64 case 'random':
65 return $name.'.'.$in;
66 break;
67 case 'custom_original':
68 return $name.'_'.$in;
69 break;
70 }
71 }
72 ?>