Repository navigation
Expand file tree
/
Copy pathcreat-post.php
More file actions
184 lines (163 loc) · 6.65 KB
/
Copy pathcreat-post.php
File metadata and controls
184 lines (163 loc) · 6.65 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<style>
.profile-img {
width: 40px;
height: 40px;
object-fit: cover;
}
.preview-image {
max-height: 300px;
object-fit: contain;
}
.preview-container {
position: relative;
display: inline-block;
}
.remove-preview {
position: absolute;
top: 10px;
right: 10px;
background: white;
border-radius: 50%;
padding: 5px 8px;
cursor: pointer;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.post-button {
transition: background-color 0.2s;
}
.post-button:hover {
background-color: #f8f9fa;
}
.custom-file-upload {
cursor: pointer;
}
.modal-content {
border-radius: 15px;
}
</style>
<div class="container mt-4">
<div class="create-post bg-white rounded shadow-sm p-3 mb-3">
<div class="d-flex align-items-center border-bottom pb-3">
<?php if ($_SESSION['image'] == null) { ?>
<img src="./assets/dumy.avif" class="rounded-circle me-2" width="36px" height="36px" alt="User">
<?php } else { ?>
<img src="<?php echo $_SESSION['image'] ?>" class="rounded-circle me-2" alt="User">
<?php }
?>
<button class="form-control bg-light border-0 text-start"
data-bs-toggle="modal"
data-bs-target="#createPostModal">
What's on your mind?
</button>
</div>
<div class="d-flex justify-content-between pt-3">
<button class="btn post-button flex-grow-1 d-flex align-items-center justify-content-center">
<i class="fas fa-video text-danger me-2"></i> Live Video
</button>
<button class="btn post-button flex-grow-1 d-flex align-items-center justify-content-center"
data-bs-toggle="modal"
data-bs-target="#createPostModal">
<i class="fas fa-images text-success me-2"></i> Photo/Video
</button>
<button class="btn post-button flex-grow-1 d-flex align-items-center justify-content-center">
<i class="fas fa-smile text-warning me-2"></i> Feeling/Activity
</button>
</div>
</div>
</div>
<!-- Create Post Modal -->
<div class="modal fade" id="createPostModal" tabindex="-1" aria-labelledby="createPostModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="createPostModalLabel">Create Post</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="posts-form.php" method="POST" enctype="multipart/form-data">
<div class="mb-3">
<input class="form-control border-0"
id="postCaption"
rows="3"
placeholder="What's on your mind?"
style="resize: none;" name="capion">
</div>
<div class="mb-3">
<label class="custom-file-upload w-100">
<div class="btn btn-light w-100">
<i class="fas fa-image me-2"></i>Add Photo/Video
</div>
<input type="file"
id="postImage"
accept="image/*"
style="display: none;" name="post_img">
</label>
</div>
<div id="previewContainer" class="mb-3 d-none">
<div class="preview-container w-100">
<img id="imagePreview" class="preview-image w-100 rounded">
<button type="button" class="btn remove-preview" id="removePreview">
<i class="fas fa-times"></i>
</button>
</div>
</div>
<button type="submit" class="btn btn-primary w-100">
Post
</button>
</form>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
const postForm = document.getElementById('postForm');
const postImage = document.getElementById('postImage');
const imagePreview = document.getElementById('imagePreview');
const previewContainer = document.getElementById('previewContainer');
const removePreview = document.getElementById('removePreview');
const modal = document.getElementById('createPostModal');
// Handle file selection and preview
postImage.addEventListener('change', function(e) {
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
imagePreview.src = e.target.result;
previewContainer.classList.remove('d-none');
}
reader.readAsDataURL(file);
}
});
// Remove preview image
removePreview.addEventListener('click', function() {
imagePreview.src = '';
postImage.value = '';
previewContainer.classList.add('d-none');
});
// Handle form submission
postForm.addEventListener('submit', function(e) {
e.preventDefault();
const formData = new FormData();
formData.append('caption', document.getElementById('postCaption').value);
if (postImage.files[0]) {
formData.append('image', postImage.files[0]);
}
// Here you would typically send the formData to your server
console.log('Form submitted:', {
caption: formData.get('caption'),
image: formData.get('image')
});
// Reset form and close modal
postForm.reset();
previewContainer.classList.add('d-none');
bootstrap.Modal.getInstance(modal).hide();
});
// Reset form when modal is closed
modal.addEventListener('hidden.bs.modal', function() {
postForm.reset();
previewContainer.classList.add('d-none');
});
});
</script>