-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.php
More file actions
59 lines (47 loc) · 1.48 KB
/
Copy pathupload.php
File metadata and controls
59 lines (47 loc) · 1.48 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
<?php
$msg = "";
if(isset($_POST['upload']))
{
$target = "images/" .basename($_FILES['image']['name']);
$db = mysqli_connect("localhost" , "root", "", "cmm007");
$image = $_FILES['image']['name'];
$text = $_POST['text'];
$sql = "INSERT INTO images (image, text) VALUES ('$image', '$text')";
mysqli_query($db, $sql);
if(move_uploaded_file($_FILES['image']['tmp_name'], $target))
{
$msg = "Image uploaded successfully";
}
else{
$msg = "There is a problem uploading image";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title> Image upload</title>
<link rel="stylesheet" type = "text/css" href ="style.css">
</head>
<body>
<div id = "content">
<?php
$db = mysqli_connect("localhost" , "root", "", "cmm007");
$sql = "SELECT * FROM images";
$result = mysqli_query($db, $sql);
while($row = mysqli_fetch_array($result))
{
echo"<div id= 'img_div'>";
echo"<img src = ' images/" .$row['image']. " ' >";
echo "<p>". $row['text']. "</p>";
echo "</div>";
} ?>
<form method = "post" action = "upload.php" enctype="multipart/form-data">
<input type = "hidden" name = "size" value = "1000000">
<div> <input type = "file" name = "image"></div>
<div><textarea name = "text" cols = "40" rows = "4" placeholder = "Write your story here..."></textarea></div>
<div><input type="submit" name ="upload" value="upload an image"></div>
</form>
</div>
</body>
</html>