uguu/core.php

24 lines
757 B
PHP
Raw Normal View History

2015-02-04 20:21:26 +01:00
<?php
function save_file ($file, $name){
2015-02-11 03:31:27 +01:00
//Generate a random prefix, strip tags and remove any whitespace
$file_name = gen_name(strip_tags(preg_replace('/\s+/', '', $name)));
2015-02-07 20:01:26 +01:00
//Where to save
2015-02-04 20:21:26 +01:00
$path='/home/neku/www/files/';
2015-02-07 20:01:26 +01:00
//Move the file to the above location with said filename
2015-02-11 03:31:27 +01:00
move_uploaded_file($file,$path.$file_name);
2015-02-07 20:01:26 +01:00
//Return url+filename to the user
2015-02-04 20:21:26 +01:00
echo 'http://a.uguu.se/'.$file_name;
}
2015-02-11 03:31:27 +01:00
Function gen_name ($in){
2015-02-11 03:43:43 +01:00
//Check so the file doesn't exist, and generate random prefix
while(file_exists('/home/neku/www/files'.$name.'_'.$in)){
2015-02-11 03:31:27 +01:00
$chars = 'abcdefghijklmnopqrstuvwxyz';
$name = '';
for ($i = 0; $i < 6; $i++) {
$name .= $chars[mt_rand(0, 25)];
2015-02-11 03:43:43 +01:00
}
2015-02-11 03:31:27 +01:00
}
return $name.'_'.$in;
}
2015-02-04 20:21:26 +01:00
?>