]> jfr.im git - uguu.git/blob - includes/core.php
29cfdb0c0d8566cca029cfa4fb5afe2a51b00365
[uguu.git] / includes / core.php
1 <?php
2 function save_file ($file, $name, $arg){
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 include_once('error_meow.php');
13 exit(0);}
14 $file_name = gen_name('random', $ext);
15 while(file_exists($path.$file_name)){
16 $file_name = gen_name('random', $ext);
17 }
18 break;
19 case 'custom_original':
20 $name = stripslashes(str_replace('/', '', $name));
21 $name = strip_tags(preg_replace('/\s+/', '', $name));
22 $file_name = gen_name('custom_original', $name);
23 $ext = pathinfo($file_name, PATHINFO_EXTENSION);
24 $ext = strtolower($ext);
25 if(in_array($ext, $block)){
26 include_once('error_meow.php');
27 exit(0);}
28 while(file_exists($path.$file_name)){
29 $file_name = gen_name('custom_original', $name);
30 }
31 break;
32 }
33 //Move the file to the above location with said filename
34 move_uploaded_file($file,$path.$file_name);
35 //Return url+filename to the user
36 echo 'http://a.uguu.se/'.urlencode($file_name);
37 }
38 function gen_name($arg, $in){
39 $chars = 'abcdefghijklmnopqrstuvwxyz';
40 $name = '';
41 for ($i = 0; $i < 6; $i++) {
42 $name .= $chars[mt_rand(0, 25)];
43 }
44 switch($arg){
45 case 'random':
46 return $name.'.'.$in;
47 break;
48 case 'custom_original':
49 return $name.'_'.$in;
50 break;
51 }
52 }
53 ?>