-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert.php
47 lines (34 loc) · 1.23 KB
/
insert.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
<?php
include './config.php';
if (isset($_POST['upload'])) {
// creates local folder for images
if(!is_dir('images')) {
mkdir('images');
};
// form data for insert
// creates unique filename
$photo=substr($_FILES['photo']['tmp_name'], 5).$_FILES['photo']['name'];
$tmp_name=$_FILES['photo']['tmp_name'];
$text=$_POST['text'];
// destination for images locally
$destination ='./images/'.$photo;
// moving the images to the destination
move_uploaded_file($tmp_name, $destination);
// insert query for database
$insert = "INSERT INTO photo (filename, text) VALUES('$photo', '$text')";
$insertQuery=mysqli_query($connphoto, $insert);
}
?>
<a href="logout.php">Log Out</a>
<form action="home.php" method="post" enctype="multipart/form-data">
<div>
<label for="photo">Choose photo</label>
<input type="file" name="photo" id="photo" accept="image/png, image/jpeg" required>
</div>
<div>
<textarea type="text" placeholder="Whats in this photo?" name="text"></textarea>
</div>
<div>
<input class="button" type="submit" name="upload" value="send it!">
</div>
</form>