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_new.php
<?php
// ==== CONFIGURATION ====
// define('UPLOAD_DIR', '/var/www/content-sp/uploads/tet_admin_photo_sp/');
define('MAX_SIZE', 1024);       // in KB
define("MIN_WIDTH", "10");
define("MIN_HEIGHT", "10");

header('Content-Type: application/json');

$errors = 0;
$msg = "";

$mType = preg_replace('/[^a-zA-Z0-9_-]/', '', $_GET['folder'] ?? 'sp');
$upload_dir = '/var/www/content-sp/uploads/tet_admin_photos_' . $mType . '/';
// Ensure file is uploaded
if (!isset($_FILES['file']) || $_FILES['file']['error'] != 0) {
    echo json_encode(['error' => 'No file uploaded or upload error.']);
    exit;
}

// Prepare data
$image = $_FILES['file']['name'];
$tmp_path = $_FILES['file']['tmp_name'];

// Get file extension
$extension = strtolower(pathinfo($image, PATHINFO_EXTENSION));
$allowed_ext = ['jpg', 'jpeg', 'png'];

if (!in_array($extension, $allowed_ext)) {
    echo json_encode(['error' => 'Invalid file type. Only JPG, JPEG, PNG allowed.']);
    exit;
}

// Validate image size and dimensions
$sizekb = filesize($tmp_path) / 1024;
$size = @getimagesize($tmp_path);
$width = $size[0];
$height = $size[1];

if ($sizekb > MAX_SIZE) {
    echo json_encode(['error' => "File too large. Max allowed size: " . MAX_SIZE . " KB"]);
    exit;
}
if ($width < MIN_WIDTH || $height < MIN_HEIGHT) {
    echo json_encode(['error' => "Minimum dimensions required: " . MIN_WIDTH . "x" . MIN_HEIGHT]);
    exit;
}

// Create upload directory if not exists
if (!file_exists($upload_dir)) {
    mkdir($upload_dir, 0755, true);
}

// Generate unique file name
$newname = time() . "_" . preg_replace("/[^a-zA-Z0-9._-]/", "_", $image);
$target_file = $upload_dir . $newname;

// Move uploaded file
if (move_uploaded_file($tmp_path, $target_file)) {
    // Construct accessible URL for TinyMCE
    $base_url = "https://content.grapossconnect.com/uploads/tet_admin_photos_" . $mType . "/"; // <-- Change this
    $file_url = $base_url . $newname;

    echo json_encode(['location' => $file_url]);
} else {
    echo json_encode(['error' => 'Failed to move uploaded file.']);
}