| Server IP : 210.245.233.93 / Your IP : 216.73.216.226 Web Server : Apache/2.2.15 (CentOS) System : Linux webserver2.onesolution.com.hk 2.6.32-754.35.1.el6.x86_64 #1 SMP Sat Nov 7 12:42:14 UTC 2020 x86_64 User : apache ( 48) PHP Version : 5.3.3 Disable Function : exec, shell_exec, system, passthru, popen, proc_open, pcntl_exec MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/hkosl.com/alliancealliance/webadmin/plupload/ |
Upload File : |
<?php
include '../config.php';
// Check if the user is logged in
if ((!isSet($_SESSION['loginname'])) || ($loggin <> '1')) {
header("Location: ../login.php");
exit;
}
require_once("../function_cropimg.php");
require_once("../mime_type_lib.php");
error_reporting(E_ALL);
ini_set('display_errors', 0);
/*if (!function_exists('random_string')) {
function random_string( $length = 8 ) {
$chars = "abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ23456789";
$random_string = substr( str_shuffle( $chars ), 0, $length );
return $random_string;
}
}*/
if (!function_exists('validate_upload_file')) {
function validate_upload_file($file){
global $targetDir;
$max_file_size_server = $_REQUEST["max_file_size_server"];
//die('{"jsonrpc" : "2.0","error" : "'.$file["name"].'"}');
//check if file empty
if(empty($file["name"]) || $file['size'] <= 0){
die('{"jsonrpc" : "2.0","error" : "Please upload a image file!"}');
}
//check file size
if ($file['size'] > $max_file_size_server) {
die('{"jsonrpc" : "2.0","error" : "You can only upload image files less than 2M!"}');
}
//check file mime type
$mime = get_file_mime_type($file["name"]);
if($_REQUEST["upload_type"] == "1"){// 1="only jpg,png,gif" , 2="only pdf", 3="only doc, excel, ppt", 4="All";
if ((strpos($mime, 'image/gif') !== false) || (strpos($mime, 'image/jpeg') !== false) || (strpos($mime, 'image/png') !== false)) {
}else{
die('{"jsonrpc" : "2.0","error" : "You can only upload image files!"}');
}
}else if($_REQUEST["upload_type"] == "2"){
if ((strpos($mime, 'application/pdf') !== false)) {
}else{
die('{"jsonrpc" : "2.0","error" : "You can only upload pdf files!"}');
}
}elseif($_REQUEST["upload_type"] == "3"){
if ((strpos($mime, 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') !== false) || (strpos($mime, 'application/vnd.openxmlformats-officedocument.presentationml.presentation') !== false) || (strpos($mime, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') !== false) || (strpos($mime, 'application/msword') !== false) || (strpos($mime, 'application/vnd.ms-powerpoint') !== false) || (strpos($mime, 'application/vnd.ms-excel') !== false)) {
}else{
die('{"jsonrpc" : "2.0","error" : "You can only upload Word/Excel/Powerpoint files!"}');
}
}elseif($_REQUEST["upload_type"] == "4"){
if ((strpos($mime, 'image/gif') !== false) || (strpos($mime, 'image/jpeg') !== false) || (strpos($mime, 'image/png') !== false) || (strpos($mime, 'application/pdf') !== false) || (strpos($mime, 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') !== false) || (strpos($mime, 'application/vnd.openxmlformats-officedocument.presentationml.presentation') !== false) || (strpos($mime, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') !== false) || (strpos($mime, 'application/msword') !== false) || (strpos($mime, 'application/vnd.ms-powerpoint') !== false) || (strpos($mime, 'application/vnd.ms-excel') !== false)) {
}else{
die('{"jsonrpc" : "2.0","error" : "You can only upload image/pdf/Word/Excel/Powerpoint files!"}');
}
}else{
exit;
}
$file_token = pathinfo($file["name"]);
$file_title = $file_token['filename'];
$file_extension = $file_token['extension'];
$file_extension_lower = strtolower($file_extension);
//check file extension
if($_REQUEST["upload_type"] == "1"){// 1="only jpg,png,gif" , 2="only pdf", 3="only doc, excel, ppt", 4="All";
$whitelist = array("jpg","jpeg","png", "gif");
}else if($_REQUEST["upload_type"] == "2"){
$whitelist = array("pdf");
}else if($_REQUEST["upload_type"] == "3"){
$whitelist = array("doc","docx","xls","xlsx","ppt","pptx");
}else if($_REQUEST["upload_type"] == "4"){
$whitelist = array("jpg","jpeg","png", "gif","pdf", "doc","docx","xls","xlsx","ppt","pptx");
}else{
exit;
}
$right_extention = 0;
foreach ($whitelist as $item) {
if($item == $file_extension_lower) {
$right_extention = 1;
break;
}
}
if($right_extention != 1){
die('{"jsonrpc" : "2.0","error" : "You cannot upload this type files!"}');
}
//rename chinese word to random string
/* if(preg_match("/\p{Han}+/u", $file_title)){
$file_title = random_string(12);
}*/
//filter special characters
$file_title = preg_replace('/\W/', '_', $file_title);
$file_name = $file_title.".".$file_extension;
$filePath = $targetDir . "/" . $file_name;
//check if file exist and rename
if (is_file($filePath)) {
$i = 1;
do {
$filePath = $targetDir . "/" . $file_title . "(" . $i . ")." . $file_extension;
$file_name = $file_title . "(" . $i . ")." .$file_extension;
$i++;
} while (is_file($filePath));
//unlink($filePath);
}
$file_info = array($file_title, $file_name, $filePath, $file_extension);
return $file_info;
}
}
// Make sure file is not cached (as it happens for example on iOS devices)
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
// 5 minutes execution time
@set_time_limit(5 * 60);
// Uncomment this one to fake upload time
// usleep(5000);
// Settings
$targetDir = 'uploads';
$cleanupTargetDir = true; // Remove old files
$maxFileAge = 5 * 3600; // Temp file age in seconds
$valid_file = 0;
//get uploader id
$uploader_id = $_REQUEST['uploader_id'];
// Get a file name
/* if (isset($_REQUEST["name"])) {
$fileName = $_REQUEST["name"];
} elseif (!empty($_FILES)) {
$fileName = $_FILES["file"]["name"];
} else {
$fileName = uniqid("file_");
}*/
$file_info = validate_upload_file($_FILES["file"]);
//check function return
if(!empty($file_info)){ //valid return
$file_title = $file_info["0"];
$file_name = $file_info["1"];
$filePath = $file_info["2"];
$file_extension = $file_info["3"];
}else{ //invalid return
exit;
}
// Chunking might be enabled
/* $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
$chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0;*/
// Open temp file
//set output file
/*if (!$out = @fopen("{$filePath}.part", $chunks ? "ab" : "wb")) {
die('{"jsonrpc" : "2.0", "error" : "Failed to open output stream."}');
}*/
if (!empty($_FILES)) {
if ($_FILES["file"]["error"] || !is_uploaded_file($_FILES["file"]["tmp_name"])) {
die('{"jsonrpc" : "2.0", "error" : "Failed to move uploaded file."}');
}
// Read binary input stream and append it to temp file
/*if (!$in = @fopen($_FILES["file"]["tmp_name"], "rb")) {
die('{"jsonrpc" : "2.0", "error" : "Failed to open input stream."}');
}*/
//}
$filename = $_FILES["file"]['name'];
move_uploaded_file($_FILES["file"]['tmp_name'], $filePath) or die('{"jsonrpc" : "2.0","error" : "Failed to move uploaded file."}');
} else {
/*if (!$in = @fopen("php://input", "rb")) {
die('{"jsonrpc" : "2.0", "error" : "Failed to open input stream."');
}*/
die('{"jsonrpc" : "2.0", "error" : "Failed to get uploaded file."}');
}
/*while ($buff = fread($in, 4096)) {
fwrite($out, $buff);
}*/
// @fclose($out);
// @fclose($in);
// Check if file has been uploaded
/*if (!$chunks || $chunk == $chunks - 1) {
// Strip the temp .part suffix off
rename("{$filePath}.part", $filePath);
}*/
//insert into table temp file
$sql = "select max(file_id) as maxid from temp_file ";
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute()) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
$row = $sth->fetch(PDO::FETCH_ASSOC);
$max_id = $row{"maxid"} + 1;
$sql = "insert into temp_file (file_id, file_name, uploader_id, createby, createdate) values (?, ?, ?, ?, ?)";
$parameters = array($max_id,$file_name,$uploader_id, $_SESSION['cmsloginid'], date("Y-m-d H:i:s"));
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
exit;
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
exit;
}
// Return Success JSON-RPC response, define the json value
die('{"jsonrpc" : "2.0","success" : "1","file_id" : "'.$max_id.'", "file_title" : "' . $file_title . '", "file_name" : "' . $file_name . '", "file_extension" : "'.$file_extension.'"}');
?>