-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsave_dog.php
96 lines (84 loc) · 3.48 KB
/
save_dog.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<link href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css" rel="stylesheet" />
<!-- Core theme CSS (includes Bootstrap)-->
<link href="css/styles.css" rel="stylesheet" />
<?php
require_once 'vendor/autoload.php';
require_once 'main.php';
require_once 'google_buckets_functions.php';
// Process form data
$name = $_POST['name'];
$description = $_POST['description'];
$picture = $_FILES['picture'];
// Generate unique file name for the uploaded file
$extension = pathinfo($picture['name'], PATHINFO_EXTENSION);
$uniqueFileName = uniqid() . '.' . $extension;
// Upload to Google Cloud Storage
$bucketName = 'pets_uploads'; // Your Google Cloud Storage Bucket Name
$uploadedImageName = uploadImageToBucket($picture['tmp_name'], $uniqueFileName, $bucketName);
if ($uploadedImageName) {
$imageUrl = retrieveImageFromBucket($uploadedImageName, $bucketName);
// Here, you can store $imageUrl in your database instead of the local file path
runDbCommand("
CREATE Pets CONTENT {
name: '$name',
image: '$imageUrl',
description: '$description'
}");
} else {
echo "Failed to upload image.";
}
?>
<!-- Display success message using Bootstrap alert -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="" />
<meta name="author" content="" />
<title>Trabalho de Web 1</title>
<!-- Favicon-->
<link rel="icon" type="image/x-icon" href="assets/favicon.ico" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<!-- Custom Google font-->
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@100;200;300;400;500;600;700;800;900&display=swap" rel="stylesheet" />
<!-- Bootstrap icons-->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css" rel="stylesheet" />
<!-- Core theme CSS (includes Bootstrap)-->
<link href="css/styles.css" rel="stylesheet" />
</head>
<body class="d-flex flex-column h-100 bg-light">
<main class="flex-shrink-0">
<!-- Navigation (You can copy the navigation bar from index.php or customize as needed) -->
<nav class="navbar navbar-expand-lg navbar-light bg-white py-3">
<div class="container px-5">
<a class="navbar-brand" href="index.php"><span class="fw-bolder text-primary">Pets do TADS</span></a>
<!-- Add other navigation links if necessary -->
</div>
</nav>
<!-- Alert Section -->
<div class="container px-5">
<div class="alert alert-success" role="alert">
Dog saved successfully!
</div>
</div>
</main>
<!-- Footer (You can copy the footer from index.php or customize as needed) -->
<footer class="bg-white py-4 mt-auto">
<div class="container px-5">
<!-- Footer Content -->
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<!-- Core theme JS-->
<script src="js/scripts.js"></script>
</body>
</html>
<!-- Redirect back to index.php -->
<script>
setTimeout(() => {
window.location.href = 'index.php';
}, 5000);
</script>