403Webshell
Server IP : 173.209.174.21  /  Your IP : 216.73.216.89
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux wcfs-server 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64
User : nodor ( 1000)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/wcfs/NAOPOS/php-api/api/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/wcfs/NAOPOS/php-api/api/upload_image.php
<?php

declare(strict_types=1);

require __DIR__ . '/helpers.php';

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    json_response(['error' => 'Method not allowed'], 405);
}

if (!isset($_FILES['image']) || !is_array($_FILES['image'])) {
    json_response(['error' => 'No image uploaded'], 400);
}

$image = $_FILES['image'];
if (($image['error'] ?? UPLOAD_ERR_NO_FILE) !== UPLOAD_ERR_OK) {
    json_response(['error' => 'Upload failed'], 400);
}

$tmpPath = (string) ($image['tmp_name'] ?? '');
if ($tmpPath === '' || !is_uploaded_file($tmpPath)) {
    json_response(['error' => 'Invalid upload'], 400);
}

$mime = mime_content_type($tmpPath) ?: '';
$allowed = [
    'image/jpeg' => 'jpg',
    'image/png' => 'png',
    'image/webp' => 'webp',
    'image/gif' => 'gif',
];

if (!isset($allowed[$mime])) {
    json_response(['error' => 'Only JPG, PNG, WEBP, and GIF images are allowed'], 400);
}

$uploadDir = __DIR__ . '/uploads/catalog';
if (!is_dir($uploadDir) && !mkdir($uploadDir, 0775, true) && !is_dir($uploadDir)) {
    json_response(['error' => 'Could not create upload folder'], 500);
}

$filename = 'catalog_' . bin2hex(random_bytes(8)) . '.' . $allowed[$mime];
$destination = $uploadDir . '/' . $filename;

if (!move_uploaded_file($tmpPath, $destination)) {
    json_response(['error' => 'Could not save uploaded image'], 500);
}

$scriptDir = rtrim(str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME'] ?? '/api')), '/');
$imageUrl = $scriptDir . '/uploads/catalog/' . $filename;

json_response([
    'ok' => true,
    'imageUrl' => $imageUrl,
]);

Youez - 2016 - github.com/yon3zu
LinuXploit