]> jfr.im git - uguu.git/blob - core.php
Update api.php
[uguu.git] / core.php
1 <?php
2 function save_file ($file, $name){
3 //Where to save
4 $path='/home/neku/www/files/';
5 //Generate prefix, put together name and remove tags/whitespace
6 $file_name = strip_tags(preg_replace('/\s+/', '', $name));
7 $file_name = gen_name($file_name);
8 while(file_exists($path.$file_name)){
9 $file_name = gen_name(file_name);
10 }
11 //Move the file to the above location with said filename
12 move_uploaded_file($file,$path.$file_name);
13 //Return url+filename to the user
14 echo 'http://a.uguu.se/'.$file_name;
15 }
16 Function gen_name ($in){
17 //Generate random prefix
18 $chars = 'abcdefghijklmnopqrstuvwxyz';
19 $name = '';
20 for ($i = 0; $i < 6; $i++) {
21 $name .= $chars[mt_rand(0, 25)];
22 }
23 return $name.'_'.$in;
24 }
25 ?>