]> jfr.im git - uguu.git/blob - includes/core.php
42f7961bed620619bcbdbb5538851e637689ae4a
[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 //Generate name depending on arg
6 switch($arg){
7 case 'random':
8 $ext = pathinfo($file.$name, PATHINFO_EXTENSION);
9 $file_name = gen_name('random', $ext);
10 while(file_exists($path.$file_name)){
11 $file_name = gen_name('random', $ext);
12 }
13 break;
14 case 'custom_original':
15 $name = stripslashes(str_replace('/', '', $name));
16 $name = strip_tags(preg_replace('/\s+/', '', $name));
17 $file_name = gen_name('custom_original', $name);
18 while(file_exists($path.$file_name)){
19 $file_name = gen_name('custom_original', $name);
20 }
21 break;
22 }
23 //Move the file to the above location with said filename
24 move_uploaded_file($file,$path.$file_name);
25 //Return url+filename to the user
26 echo 'http://a.uguu.se/'.urlencode($file_name);
27 }
28 function gen_name($arg, $in){
29 $chars = 'abcdefghijklmnopqrstuvwxyz';
30 $name = '';
31 for ($i = 0; $i < 6; $i++) {
32 $name .= $chars[mt_rand(0, 25)];
33 }
34 switch($arg){
35 case 'random':
36 return $name.'.'.$in;
37 break;
38 case 'custom_original':
39 return $name.'_'.$in;
40 break;
41 }
42 }
43 ?>