uguu/includes/core.php

72 lines
2.4 KiB
PHP
Raw Normal View History

2015-02-18 15:11:42 +01:00
<?php
2015-10-07 22:56:03 +02:00
function save_file ($file, $name, $arg, $type){
2015-02-11 18:17:43 +01:00
//Where to save
$path='/home/neku/www/files/';
2015-10-06 00:44:30 +02:00
$block = array('exe', 'scr', 'rar', 'zip', 'com', 'vbs', 'bat', 'cmd', 'html', 'htm', 'msi');
2015-02-11 18:17:43 +01:00
//Generate name depending on arg
switch($arg){
case 'random':
$ext = pathinfo($file.$name, PATHINFO_EXTENSION);
2015-10-06 00:44:30 +02:00
$ext = strtolower($ext);
if(in_array($ext, $block)){
2015-10-07 22:56:03 +02:00
if($type==='normal'){
2015-10-06 01:04:22 +02:00
include_once('error_meow.php');
2015-10-07 22:56:03 +02:00
exit(0);
}else{
exit('File type not allowed.');
}
}
2015-02-11 18:17:43 +01:00
$file_name = gen_name('random', $ext);
while(file_exists($path.$file_name)){
$file_name = gen_name('random', $ext);
}
break;
case 'custom_original':
2015-04-05 22:44:41 +02:00
$name = stripslashes(str_replace('/', '', $name));
2015-02-11 18:17:43 +01:00
$name = strip_tags(preg_replace('/\s+/', '', $name));
2015-10-06 00:44:30 +02:00
$file_name = gen_name('custom_original', $name);
$ext = pathinfo($file_name, PATHINFO_EXTENSION);
$ext = strtolower($ext);
if(in_array($ext, $block)){
2015-10-07 22:56:03 +02:00
if($type==='normal'){
include_once('error_meow.php');
exit(0);
}else{
exit('File type not allowed.');
}
}
2015-02-11 18:17:43 +01:00
while(file_exists($path.$file_name)){
$file_name = gen_name('custom_original', $name);
}
break;
}
//Move the file to the above location with said filename
move_uploaded_file($file,$path.$file_name);
2015-10-08 00:27:39 +02:00
//Check if html or plain text should be returned
if($type==='tool'){
//Return url+filename to the user (plain text)
2015-02-18 15:12:28 +01:00
echo 'http://a.uguu.se/'.urlencode($file_name);
2015-10-08 00:27:39 +02:00
exit(0);
}elseif($type==='normal'){
//Return url+filename to the user (HTML)
$n=urlencode($file_name);
include_once('/home/neku/www/page/public/upload-done.php');
exit(0);
}
2015-02-11 18:17:43 +01:00
}
function gen_name($arg, $in){
$chars = 'abcdefghijklmnopqrstuvwxyz';
$name = '';
for ($i = 0; $i < 6; $i++) {
$name .= $chars[mt_rand(0, 25)];
}
switch($arg){
case 'random':
return $name.'.'.$in;
break;
case 'custom_original':
return $name.'_'.$in;
break;
}
}