add post php

This commit is contained in:
mpabi 2024-10-10 15:04:12 +02:00
parent 19265c6358
commit 5c7661e2d6
2 changed files with 23 additions and 13 deletions

10
php/__ Normal file
View File

@ -0,0 +1,10 @@
curl -X POST http://192.168.80.31:8080/p10.10/php/post.php \
-H "Content-Type: application/json" \
-d '{
"ln": "Kowalski",
"fn": "Jan",
"email": "jan.kowalski@example.com",
"subject": "Test subject",
"path": "/path/to/photo.jpg"
}'

View File

@ -1,14 +1,14 @@
<?php
$polaczenie = mysqli_connect("172.19.0.3", "root", "secret", "bazqq");
$imie = $_POST['imie'];
$nazwisko = $_POST['nazwisko'];
$email = $_POST['email'];
$photo = $_FILES['photo']['tmp_name'];
$photoContent = null;
if (is_uploaded_file($photo)) {
$photoContent = addslashes(file_get_contents($photo));
}
$kwerenda = "INSERT INTO dane (imie, nazwisko, email, photo) VALUES ('$imie', '$nazwisko', '$email', '$photoContent')";
mysqli_query($polaczenie, $kwerenda);
echo json_encode($response);
$con = mysqli_connect("192.168.80.31", "root", "secret", "db");
$rawData = file_get_contents('php://input');
$data = json_decode($rawData, true);
$kw = "INSERT INTO Persons (LastName, FirstName, Email, Subject, Path) VALUES ('{$data['ln']}', '{$data['fn']}', '{$data['email']}', '{$data['subject']}', '{$data['path']}')";
$ans = mysqli_query($con, $kw);
echo json_encode($kw);
?>