403Webshell
Server IP : 103.48.194.25  /  Your IP : 216.73.216.231
Web Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.33
System : Linux VMHostDefault 3.10.0-1160.42.2.el7.x86_64 #1 SMP Tue Sep 7 14:49:57 UTC 2021 x86_64
User : sieuthimay ( 1016)
PHP Version : 8.2.20
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/pundarikanail.com-bk/site/helpers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/pundarikanail.com-bk/site/helpers/img_helper.php
<?php
function upload($uploadfile, $dir='uploads/temp/', $max_size=5242880)
{
	$up_path = create_dir();
	$size = $_FILES[$uploadfile]['size']; 
	if($size>$max_size)
	{
		$res['code'] = 0 ;
		$res['message']= "Kích thước ảnh phải nhỏ hơn 5MB";
		@unlink($_FILES[$uploadfile]['tmp_name']);
		return $res ;
	}
	else
	{            
		$filename = stripslashes($_FILES[$uploadfile]['name']);
		$path_info = pathinfo($filename); 
		$extension = strtolower($path_info['extension']);
		if($extension =='jpeg')
		{
			$extension = 'jpg';
		}
		
		$filename = substr(locdau($filename),0,15) ;
		$filename = str_replace($extension,'', $filename).'_'.time().'.'.$extension;
		$up_path = $up_path.$filename ; 
		$fullpath = $dir.$filename ;
		if (move_uploaded_file($_FILES[$uploadfile]['tmp_name'], $up_path)) 
		{
			@copy($up_path, $fullpath) ;
			//return json
			$res['code'] = 1;
			$res['message'] = "Tải ảnh thành công!";
			$res['filename'] = $filename;
		}else {
			$res['code']=0;
        	$res['filename']="";
			$res['message']="Lỗi trong quá trình upload. Vui lòng thử lại.";
		}
		return $res ;
	}
	return $res ;
}
function locdau($str)
{
	$str = preg_replace("/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/", 'a', $str);
	$str = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/", 'e', $str);
	$str = preg_replace("/(ì|í|ị|ỉ|ĩ)/", 'i', $str);
	$str = preg_replace("/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/", 'o', $str);
	$str = preg_replace("/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/", 'u', $str);
	$str = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ)/", 'y', $str);
	$str = preg_replace("/(đ)/", 'd', $str);
	$str = preg_replace("/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/", 'A', $str);
	$str = preg_replace("/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", 'E', $str);
	$str = preg_replace("/(Ì|Í|Ị|Ỉ|Ĩ)/", 'I', $str);
	$str = preg_replace("/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/", 'O', $str);
	$str = preg_replace("/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/", 'U', $str);
	$str = preg_replace("/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/", 'Y', $str);
	$str = preg_replace("/(Đ)/", 'D', $str);
	$str = preg_replace("/( )/", '-', $str);
	$str = preg_replace("/(\'|\"|`|&|,|\.|\?)/", '', $str);
	$str = preg_replace("/(---|--)/", '-', $str);
	
	$pattern = '/([^a-z0-9\-\._])/i';
	$str = preg_replace($pattern, '', $str);
		
	$str = strtolower($str);
	return $str;
}
function fn_resize_image($src, $dest, $new_width = 0, $new_height = 0, $make_box = true, $bg_color = '#ffffff', $save_original = false)
{

    
    static $notification_set = false;
    static $gd_settings = array();

    if (file_exists($src) && !empty($dest) && (!empty($new_width) || !empty($new_height)) && extension_loaded('gd')) {

        $img_functions = array(
            'png' => function_exists('imagepng'),
            'jpg' => function_exists('imagejpeg'),
            'gif' => function_exists('imagegif'),
        );
        /*
        if (empty($gd_settings)) {
            $gd_settings = fn_get_settings('Thumbnails');
        }
        */

        $dst_width = $new_width;
        $dst_height = $new_height;

        list($width, $height, $mime_type) = fn_get_image_size($src);
        if (empty($width) || empty($height)) {
            return false;
        }

        if ($width < $new_width) {
            $new_width = $width;
        }
        if ($height < $new_height) {
            $new_height = $height;
        }

        if ($dst_height == 0) { // if we passed width only, calculate height
            $new_height = $dst_height = ($height / $width) * $new_width;

        } elseif ($dst_width == 0) { // if we passed height only, calculate width
            $new_width = $dst_width = ($width / $height) * $new_height;

        } else { // we passed width and height, limit image by height! (hm... not sure we need it anymore?)
            if ($new_width * $height / $width > $dst_height) {
                $new_width = $width * $dst_height / $height;
            }
            $new_height = ($height / $width) * $new_width;
            if ($new_height * $width / $height > $dst_width) {
                $new_height = $height * $dst_width / $width;
            }
            $new_width = ($width / $height) * $new_height;
        }

        $w = number_format($new_width, 0, ',', '');
        $h = number_format($new_height, 0, ',', '');

        $ext = fn_get_image_extension($mime_type);

        if (!empty($img_functions[$ext])) {
            if ($make_box) {
                $dst = imagecreatetruecolor($dst_width, $dst_height);
            } else {
                $dst = imagecreatetruecolor($w, $h);
            }
            if (function_exists('imageantialias')) {
                imageantialias($dst, true);
            }
        } elseif ($notification_set == false) {
            $msg = fn_get_lang_var('error_image_format_not_supported');
            $msg = str_replace('[format]', $ext, $msg);
            fn_set_notification('E', fn_get_lang_var('error'), $msg);
            $notification_set = true;
            return false;
        }

        if ($ext == 'gif' && $img_functions[$ext] == true) {
            $new = imagecreatefromgif($src);
        } elseif ($ext == 'jpg' && $img_functions[$ext] == true) {
            $new = imagecreatefromjpeg($src);
        } elseif ($ext == 'png' && $img_functions[$ext] == true) {
            $new = imagecreatefrompng($src);
        } else {
            return false;
        }

        // Set transparent color to white
        // Not sure that this is right, but it works
        // FIXME!!!
        // $c = imagecolortransparent($new);

        list($r, $g, $b) = fn_parse_rgb($bg_color);
        $c = imagecolorallocate($dst, $r, $g, $b);
        //imagecolortransparent($dst, $c);
        if ($make_box) {
            imagefilledrectangle($dst, 0, 0, $dst_width, $dst_height, $c);
            $x = number_format(($dst_width - $w) / 2, 0, ',', '');
            $y = number_format(($dst_height - $h) / 2, 0, ',', '');
        } else {
            imagefilledrectangle($dst, 0, 0, $w, $h, $c);
            $x = 0;
            $y = 0;
        }
        imagecopyresampled($dst, $new, $x, $y, 0, 0, $w, $h, $width, $height);
        
        //if ($gd_settings['convert_to'] == 'original') {
            $gd_settings['convert_to'] = $ext;
       // }

        if (empty($img_functions[$gd_settings['convert_to']])) {
            foreach ($img_functions as $k => $v) {
                if ($v == true) {
                    $gd_settings['convert_to'] = $k;
                    break;
                }
            }
        }

        $pathinfo = pathinfo($dest);
        $new_filename = $pathinfo['dirname'] . '/' . basename($pathinfo['basename'], empty($pathinfo['extension']) ? '' : '.' . $pathinfo['extension']);
        
        // Remove source thumbnail file
        /*
        if (!$save_original) {
            fn_rm($src);
        }
        */

        switch ($gd_settings['convert_to']) {
            case 'gif':
                $new_filename .= '.gif';
                imagegif($dst, $new_filename);
                break;
            case 'jpg':
                $new_filename .= '.jpg';
                imagejpeg($dst, $new_filename, 90);
                break;
            case 'png':
                $new_filename .= '.png';
                imagepng($dst, $new_filename);
                break;
        }
        $dest = $new_filename;
        @chmod($dest, '775');

        return true;
    }

    return false;
}

//
// Check supported GDlib formats
//
function fn_check_gd_formats()
{
    $avail_formats = array(
        'original' => fn_get_lang_var('same_as_source'),
    );

    if (function_exists('imagegif')) {
        $avail_formats['gif'] = 'GIF';
    }
    if (function_exists('imagejpeg')) {
        $avail_formats['jpg'] = 'JPEG';
    }
    if (function_exists('imagepng')) {
        $avail_formats['png'] = 'PNG';
    }

    return $avail_formats;
}

//
// Get image extension by MIME type
//
function fn_get_image_extension($image_type)
{
    static $image_types = array (
        'image/gif' => 'gif',
        'image/pjpeg' => 'jpg',
        'image/jpeg' => 'jpg',
        'image/png' => 'png',
        'application/x-shockwave-flash' => 'swf',
        'image/psd' => 'psd',
        'image/bmp' => 'bmp',
    );

    return isset($image_types[$image_type]) ? $image_types[$image_type] : false;
}

//
// Getimagesize wrapper
// Returns mime type instead of just image type
// And doesn't return html attributes
function fn_get_image_size($file)
{
    // File is url, get it and store in temporary directory
    if (strpos($file, '://') !== false) {
        $tmp = fn_create_temp_file();

        if (fn_put_contents($tmp, fn_get_contents($file)) == 0) {
            return false;
        }

        $file = $tmp;
    }

    list($w, $h, $t, $a) = @getimagesize($file);

    if (empty($w)) {
        return false;
    }

    $t = image_type_to_mime_type($t);

    return array($w, $h, $t);
}

function fn_attach_image_pairs($name, $object_type, $object_id = 0, $lang_code = CART_LANGUAGE, $object_ids = array (), $parent_object = '', $parent_object_id = 0)
{
    $icons = fn_filter_uploaded_data($name . '_image_icon');
    $detailed = fn_filter_uploaded_data($name . '_image_detailed');
    $pairs_data = !empty($_REQUEST[$name . '_image_data']) ? $_REQUEST[$name . '_image_data'] : array();

    return fn_update_image_pairs($icons, $detailed, $pairs_data, $object_id, $object_type, $object_ids, $parent_object, $parent_object_id, true, $lang_code);
}

function fn_generate_thumbnail($image_path, $width, $height = 0, $make_box = false)
{
    if (empty($image_path)) {
        return '';
    }
    
    if (strpos($image_path, '://') === false) {
        if (strpos($image_path, '/') !== 0) { // relative path
            $image_path = Registry::get('config.current_path') . '/' . $image_path;
        }
        $image_path = (defined('HTTPS') ? ('https://' . Registry::get('config.https_host')) : ('http://' . Registry::get('config.http_host'))) . $image_path;
    }

    $_path = str_replace(Registry::get('config.current_location') . '/', '', $image_path);

    $image_url = explode('/', $_path);
    $image_name = array_pop($image_url);
    $image_dir = array_pop($image_url);
    $image_dir .= '/' . $width . (empty($height) ? '' : '/' . $height);
    $filename = $image_dir . '/' . $image_name;
    $real_path = htmlspecialchars_decode(DIR_ROOT . '/' . $_path, ENT_QUOTES);
    $th_path = htmlspecialchars_decode(DIR_THUMBNAILS . $filename, ENT_QUOTES);

    if (!fn_mkdir(DIR_THUMBNAILS . $image_dir)) {
        return '';
    }

    if (!file_exists($th_path)) {
        if (fn_get_image_size($real_path)) {
            $image = fn_get_contents($real_path);
            fn_put_contents($th_path, $image);
            fn_resize_image($th_path, $th_path, $width, $height, $make_box, Registry::get('settings.Thumbnails.thumbnail_background_color'));
            $filename_info = pathinfo($filename);
            $th_path_info = pathinfo($th_path);
            $filename = $filename_info['dirname'] . '/' . $th_path_info['basename'];
        } else {
            return '';
        }
    }

    return Registry::get('config.thumbnails_path') . $filename;
}

function fn_parse_rgb($color)
{
    $r = hexdec(substr($color, 1, 2));
    $g = hexdec(substr($color, 3, 2));
    $b = hexdec(substr($color, 5, 2));
    return array($r, $g, $b);
}

function fn_find_valid_image_path($image_pair, $object_type, $get_flash, $lang_code)
{
    if (isset($image_pair['icon']['absolute_path']) && is_file($image_pair['icon']['absolute_path'])) {
        if (!$get_flash && isset($image_pair['icon']['is_flash']) && $image_pair['icon']['is_flash']) {
            // We don't need Flash at all -- no need to crawl images any more.
            return false;
        } else {
            return $image_pair['icon']['image_path'];
        }
    }

    // Try to get the product's image.
    if (!empty($image_pair['image_id'])) {
        $image = fn_get_image($image_pair['image_id'], $object_type, 0, $lang_code);

        if (isset($image['absolute_path']) && is_file($image['absolute_path'])) {
            if (!$get_flash && isset($image['is_flash']) && $image['is_flash']) {
                return false;
            }

            return $image['image_path'];
        }
    }

    // If everything above failed, try to generate the thumbnail.
    if (!empty($image_pair['detailed_id'])) {
        $image = fn_get_image($image_pair['detailed_id'], 'detailed', 0, $lang_code);

        if (isset($image['absolute_path']) && is_file($image['absolute_path'])) {
            if (isset($image['is_flash']) && $image['is_flash']) {
                if ($get_flash) {
                    // No need to call fn_generate_thumbnail()
                    return $image['image_path'];
                } else {
                    return false;
                }
            }

            $image = fn_generate_thumbnail($image['image_path'], Registry::get('settings.Thumbnails.product_details_thumbnail_width'), Registry::get('settings.Thumbnails.product_details_thumbnail_height'), false);
            if (!empty($image)) {
                return $image;
            }
        }
    }

    return false;
}

function fn_convert_relative_to_absolute_image_url($image_path)
{
    return 'http://' . Registry::get('config.http_host') . $image_path;
}

function fn_show_banner($filename, $link='', $w='', $h='', $title='', $id='bnqc'){
	
	$ext = file_extension($filename);
	$w = !empty($w) ? ' width='.$w.'px' : '' ;
	$h = !empty($h) ? ' height='.$h.'px' : '' ;
	$title = !empty($title) ? ' title='.$title : '' ;
	$id = !empty($id) ? ' id='.$id : '' ;
	
	switch($ext){
		case "swf" :
			$img='<a href="'.$link.'" target="_blank" '.$title.'><embed '.$h.' '.$w.' src="'.$filename.'" wmode="transparent" rel="'.$link.'" '.$id.' /></a>' ;
			break ;
		default :
			$img='<a href="'.$link.'" target="_blank" '.$title.' '.$id.'><img src="'.$filename.'" border=0 '.$h.' '.$w.' '.$title.' '.$id.' /></a>' ;
			break ;
	}
	return $img ;
}
function file_extension($filename)
{
    $path_info = pathinfo($filename); 
    return $path_info['extension'];
}
function create_dir()
{
	$date_path 	= date('Y').'/'.date('m');
	$up_path 	= $date_path.'/'; 
	if(!is_dir(ROOT_IMG.$up_path)){
		@mkdir(ROOT_IMG.$up_path,0777, true);
	}
	return $up_path;
}
?>

Youez - 2016 - github.com/yon3zu
LinuXploit