HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-31-18-78 6.17.0-1017-aws #17~24.04.1-Ubuntu SMP Tue May 26 21:09:53 UTC 2026 aarch64
User: ubuntu (1000)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: /var/www/content-sp/work-sp/nqb_upload_image.php
<?php
include_once('header.php');
// ini_set('display_errors',1);
// ini_set('display_startup_errors',1);
// error_reporting(E_ALL);
$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$root_link = $protocol . $_SERVER['HTTP_HOST'] . '/';
$mType = $_REQUEST['mType'];

if (!isset($_REQUEST['popup'])) {

    // To change the user image
    //define a maxim size for the uploaded images
    define("MAX_SIZE", 2000);
    // define the width and height for the thumbnail
    // note that theese dimmensions are considered the maximum dimmension and are not fixed,
    // because we have to keep the image ratio intact or it will be deformed
    define("WIDTH", "150");
    define("HEIGHT", "150");
    define("MIN_WIDTH", "10");
    define("MIN_HEIGHT", "10");
    define("DIMENSION", "150");
    $curTime = date('ymdHis');


    //echo "PATH". $upload_path;

    // this is the function that will create the thumbnail image from the uploaded image
    // the resize will be done considering the width and height defined, but without deforming the image
    function make_thumb($src_image, $dest_image, $thumb_size = DIMENSION, $jpg_quality = 90)
    {

        // Get dimensions of existing image
        $image = getimagesize($src_image);

        // Check for valid dimensions
        if ($image[0] <= 0 || $image[1] <= 0) return false;

        // Determine format from MIME-Type
        $image['format'] = strtolower(preg_replace('/^.*?\//', '', $image['mime']));

        // Import image
        switch ($image['format']) {
            case 'jpg':
            case 'jpeg':
                $image_data = imagecreatefromjpeg($src_image);
                break;
            case 'png':
                $image_data = imagecreatefrompng($src_image);
                break;
            case 'gif':
                $image_data = imagecreatefromgif($src_image);
                break;
            default:
                // Unsupported format
                return false;
                break;
        }

        // Verify import
        if ($image_data == false) return false;

        // Calculate measurements
        if ($image[0] > $image[1]) {
            // For landscape images
            $x_offset = ($image[0] - $image[1]) / 2;
            $y_offset = 0;
            $square_size = $image[0] - ($x_offset * 2);
            log_message('debug', '95 landscape images' . $image[0] . $image[1] . $square_size);
        } else {
            // For portrait and square images
            $x_offset = 0;
            $y_offset = ($image[1] - $image[0]) / 2;
            $square_size = $image[1] - ($y_offset * 2);
            log_message('debug', '105 portrait and square images' . $square_size);
        }

        // Resize and crop
        $canvas = imagecreatetruecolor($thumb_size, $thumb_size);

        //$whitebackground = imagecolorallocate($canvas,255,255,255);
        //imagefill($canvas, 0, 0, $whitebackground);

        if (imagecopyresampled(
            $canvas,
            $image_data,
            0,
            0,
            $x_offset,
            $y_offset,
            $thumb_size,
            $thumb_size,
            $square_size,
            $square_size
        )) {

            // Create thumbnail
            switch (strtolower(preg_replace('/^.*\./', '', $dest_image))) {
                case 'jpg':
                case 'jpeg':
                    return imagejpeg($canvas, $dest_image, $jpg_quality);
                    break;
                case 'png':
                    return imagepng($canvas, $dest_image);
                    break;
                case 'gif':
                    return imagegif($canvas, $dest_image);
                    break;
                default:
                    // Unsupported format
                    return false;
                    break;
            }
        } else {
            return false;
        }
    }

    // This function reads the extension of the file.
    // It is used to determine if the file is an image by checking the extension.
    function getExtension($str)
    {
        $i = strrpos($str, ".");
        if (!$i) {
            return "";
        }
        $l = strlen($str) - $i;
        $ext = substr($str, $i + 1, $l);
        return $ext;
    }

    // This variable is used as a flag. The value is initialized with 0 (meaning no error found)
    //and it will be changed to 1 if an errro occures. If the error occures the file will not be uploaded.
    $errors = 0;
    $copied = "";
    // checks if the form has been submitted
    if (isset($_POST['btn_upload'])) {


        $msg = "";
        //reads the name of the file the user submitted for uploading
        $image = $_FILES['image']['name'];
        $mType_check = $_REQUEST['mType_check'] != '0' ? $_REQUEST['mType_check'] : $mType;

        $upload_path = '/var/www/content-sp/uploads/tet_admin_photos_' . $mType_check . '/';
        // if it is not empty
        if ($image) {
            // get the original name of the file from the clients machine
            $filename = stripslashes($_FILES['image']['name']);

            // get the extension of the file in a lower case format
            $extension = getExtension($filename);
            $extension = strtolower($extension);
            // if it is not a known extension, we will suppose it is an error, print an error message
            //and will not upload the file, otherwise we continue
            if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) {
                $msg .= "Sorry unknown extension!" . '<br>';
                $errors = 1;
            } else {
                // get the size of the image in bytes
                // $_FILES[\'image\'][\'tmp_name\'] is the temporary filename of the file in which the uploaded file was stored on the server
                $size = getimagesize($_FILES['image']['tmp_name']);
                $width = $size[0];
                $height = $size[1];

                $sizekb = filesize($_FILES['image']['tmp_name']);

                //compare the size with the maxim size we defined and print error if bigger
                if ($sizekb > MAX_SIZE * 1024) {
                    $msg .= "Your image is too large please reduce your image size below " . MAX_SIZE . "kb";
                    $errors = 1;
                }
                //compare the size with the minimum  we defined and print error if bigger
                if ($height < MIN_HEIGHT || $width < MIN_WIDTH) {
                    $msg .= "Minimum " . MIN_HEIGHT . 'X' . MIN_WIDTH . " dimension is required for image!";
                    $errors = 1;
                }

                //we will give an unique name, for example the time in unix time format
                $image_name = $curTime . "_" . $_FILES['image']['name'];
                //the new name will be containing the full path where will be stored (images folder)

                if (!file_exists($upload_path)) {
                    mkdir($upload_path);
                }
                $newname = $upload_path . $image_name;
                echo "newn" . $newname;
                //$upload = ABSPATH."wp-content/plugins/mam_auction/images/".$newname;
                if ($errors != 1) {
                    //$copied = copy($_FILES['image']['tmp_name'], $newname);
                    //$copied = copy(WP_UPLOAD_DIR.$image_name); 
                    //move_uploaded_file($image_name,$upload_path);
                    $target_file = $upload_path . $image_name;
                    if (move_uploaded_file($_FILES['image']["tmp_name"], $target_file)) {
                        echo "copied" . $target_file;
                        //$wpdb->query( "UPDATE  $MAM_AUCTION_USER_DETAIL_TABLE SET  image = '$image_name'  WHERE user_id ='$user_id' ");
                        $msg = "Image uploaded successfully<br> Uploaded Image URL : " . $root_link . 'uploads/tet_admin_photos_' . $mType_check . '/' . $image_name;
                    } else {
                        $msg = "Not uploaded";
                    }
                }
                if (!$copied) {
                    $errors = 1;
                }
            }
        }
    }
} else {
    include_once('../config.php');
    $upload_path = '/var/www/content-sp/uploads/tet_admin_photos_' . $mType . '/';
}

if ($mType == 'sp') {
    $text = 'Note : You are uploading image for Sarkari Pariksha - <a href="nqb_upload_image?mType=oly">Click Here</a> for Csc Olympiad image';
} else if ($mType == 'oly') {
    $text = 'Note : You are uploading image for CscOlympiad - <a href="nqb_upload_image?mType=sp">Click Here</a> for Sarkari Pariksha image';
}

?>

<div class="page-inner">
    <div class="page-title">
        <h3>Upload Image</h3>
        <div class="page-breadcrumb">
            <ol class="breadcrumb">
                <li><a href="dashboard">Home</a></li>
                <li class="active">Upload Image</li>
            </ol>
        </div>
    </div>
    <div id="main-wrapper">
        <div class="row">
            <div class="col-md-12">
                <div class="panel panel-white">
                    <div class="panel-body">
                        <?php if ($mType == 'sp' || $mType == 'oly') { ?>
                            <form method="POST" class="form-horizontal" enctype="multipart/form-data" data-default="150" onsubmit="return valiDateUpload();">
                                <div class="form-group">
                                    <label for="mType_check" class="col-sm-2 control-label">Upload For</label>
                                    <div class="col-sm-4">
                                        <select name="mType_check" id="mType_check" class="form-control">
                                            <option value="0">--Select To Upload--</option>
                                            <option value="sp">Sarkari Pariksha</option>
                                            <option value="oly">Olympiad</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="fileTo" class="col-sm-2 control-label">Browse File</label>
                                    <div class="col-sm-4">
                                        <input type="file" name="image" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="fileTo" class="col-sm-2 control-label"></label>
                                    <div class="col-sm-4">
                                        <button class="btn btn-success" type="submit" name="btn_upload"><i class="fa fa-upload"></i></button>
                                    </div>
                                </div>
                                <?php if ($editor_role != '5') { ?>
                                    <div class="form-group">
                                        <label class="error" for="">
                                            <?php echo $text; ?>
                                        </label>
                                    </div>
                                <?php } ?>
                            </form><!-- Search Form -->
                        <?php } else {  ?>
                            <label class="error" for="">Something went wrong go this url for Sarkari Pariksha Image
                                <a href="nqb_upload_image?mType=sp">Click Here</a> for Csc Olympiad image <a href="nqb_upload_image?mType=oly">Click Here</a>
                            </label>
                        <?php } ?>
                    </div>
                </div>
            </div>
            <div class="col-md-12">
                <label class="error" style="display: block;"><?php if (isset($msg)) {
                                                                    echo $msg;
                                                                } ?></label>
            </div>
        </div>
    </div>
    <div class="page-footer">
        <p class="no-s">sarkaripariksha.com</p>
    </div>
</div>
<?php
include_once('footer.php');
?>
<script>
    function valiDateUpload() {

        if (jQuery("#mType_check").val() == 0) {
            alert("Please select dropdown");
            return false;
        }

    }
</script>