/
AlexeyS_AS
/
Gerber-TEST
Обзор
Документация
Войти
/
AlexeyS_AS
/
Gerber-TEST
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
php/test_2/process.php
115 строк
4 KB
Alexey Karizhenskiy
Прочие правки..
13 апр 2025, 12:31
13 апр 2025, 12:31
b549671
Код
Авторство
О чём код?
<!DOCTYPE html> <html> <head> <title>Результаты обработки Gerber</title> <style> body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; } .results { margin-top: 20px; padding: 20px; border: 1px solid #ddd; border-radius: 4px; } .back-btn { display: inline-block; margin-top: 20px; padding: 10px 20px; background-color: #4CAF50; color: white; text-decoration: none; border-radius: 4px; } </style> </head> <body> <?php require_once(__DIR__ . '/vendor/autoload.php'); //require_once(__DIR__ . '/src/Gerber.php'); if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['gerber_file'])) { $uploadDir = 'uploads/'; $imagesDir = 'uploads/images/'; if (!file_exists($uploadDir)) { mkdir($uploadDir, 0777, true); } if (!file_exists($imagesDir)) { mkdir($imagesDir, 0777, true); } ?> <h1>Результаты обработки</h1> <div class="results"> <?php $file = $_FILES['gerber_file']; $fileName = basename($file['name']); $targetPath = $uploadDir . $fileName; if (move_uploaded_file($file['tmp_name'], $targetPath)) { try { $gerber = new \Igloo\Gerber\Gerber($targetPath, $imagesDir); $gerber->process(); // Получаем данные из объекта $gerber $arSize = $gerber->getSize(); $arImages = $gerber->getImage(); $arImagesByLayers = $gerber->getImagesByLayers(); if (!empty($arSize)) { // Извлекаем размеры платы $boardWidth = isset($arSize['file']['x']) ? htmlspecialchars($arSize['file']['x']) : 'Не указано'; $boardHeight = isset($arSize['file']['y']) ? htmlspecialchars($arSize['file']['y']) : 'Не указано'; $boardUnits = isset($arSize['file']['units']) ? htmlspecialchars($arSize['file']['units']) : 'Не указано'; // Извлекаем размеры изображения $imageWidth = isset($arSize['image']['x']) ? htmlspecialchars($arSize['image']['x']) : 'Не указано'; $imageHeight = isset($arSize['image']['y']) ? htmlspecialchars($arSize['image']['y']) : 'Не указано'; $imageUnits = isset($arSize['image']['units']) ? htmlspecialchars($arSize['image']['units']) : 'Не указано'; // Создаем HTML для отображения результатов echo ' <h2>Размеры платы:</h2> <p>Ширина: ' . $boardWidth . ' ' . $boardUnits . '</p> <p>Высота: ' . $boardHeight . ' ' . $boardUnits . '</p> <h2>Размеры изображения:</h2> <p>Ширина: ' . $imageWidth . ' ' . $imageUnits . '</p> <p>Высота: ' . $imageHeight . ' ' . $imageUnits . '</p>'; // Если есть изображения по слоям, добавляем их if (!empty($arImagesByLayers)) { echo '<h2>Изображения по слоям:</h2>'; foreach ($arImagesByLayers as $layer => $imagePath) { echo '<p>' . htmlspecialchars($layer) . ': <br><img width="240px" src="' . $imagesDir . htmlspecialchars($imagePath) . '" alt="' . htmlspecialchars($layer) . ' превью" class="image-preview"></p>'; } } } else { echo '<h2>Ошибка обработки: результаты отсутствуют</h2>'; } } catch (Exception $e) { echo "Ошибка при обработке файла: " . $e->getMessage(); } } else { echo "Ошибка при загрузке файла"; } } else { echo "Файл не загружен"; //header("Location: ./"); //exit(); } ?> </div> <a href="./" class="back-btn">Назад к загрузке</a> </body> </html>