$newName, 'url' => $protocol . $domain . $path . '/' . $dest ]; } else { $errors[] = "ไม่สามารถบันทึกไฟล์: $origName"; } } else { $errors[] = "ไม่รองรับนามสกุลไฟล์: $origName"; } } } echo json_encode(['status' => 'done', 'uploaded' => $uploaded, 'errors' => $errors]); exit; } if ($is_logged_in && isset($_GET['delete'])) { $fileToDelete = basename($_GET['delete']); $filePath = $UPLOAD_DIR . $fileToDelete; if (file_exists($filePath)) { unlink($filePath); } header("Location: " . strtok($_SERVER["REQUEST_URI"], '?')); exit; } $images = []; if ($is_logged_in && is_dir($UPLOAD_DIR)) { $files = scandir($UPLOAD_DIR); foreach ($files as $file) { $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION)); if (in_array($ext, $ALLOWED_EXT)) { $images[] = [ 'name' => $file, 'path' => $UPLOAD_DIR . $file, 'time' => filemtime($UPLOAD_DIR . $file), 'size' => round(filesize($UPLOAD_DIR . $file) / 1024 / 1024, 2) ]; } } usort($images, function($a, $b) { return $b['time'] - $a['time']; }); } $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https://" : "http://"; $baseUrl = $protocol . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . '/'; ?>
รองรับ JPG, PNG, WebP, GIF, SVG • กด Ctrl+V เพื่อวางรูปได้ทันที