]> jfr.im git - uguu.git/blob - includes/core.php
7a1e4d621dcfad15224f97ea022ed7e0a7b86178
[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 //Return url+filename to the user
46 echo 'http://a.uguu.se/'.urlencode($file_name);
47 }
48 function gen_name($arg, $in){
49 $chars = 'abcdefghijklmnopqrstuvwxyz';
50 $name = '';
51 for ($i = 0; $i < 6; $i++) {
52 $name .= $chars[mt_rand(0, 25)];
53 }
54 switch($arg){
55 case 'random':
56 return $name.'.'.$in;
57 break;
58 case 'custom_original':
59 return $name.'_'.$in;
60 break;
61 }
62 }
63 ?>