-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpinphoto.php
100 lines (97 loc) · 3.28 KB
/
pinphoto.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
97
98
99
100
<html>
<head>
<title>User Profile</title>
<link rel='stylesheet' href='style.css' />
</head>
<body>
<?php include 'connect.php'; ?>
<?php include 'function.php'; ?>
<?php include 'header.php';?>
<div class='container'>
<?php include 'title_bar.php';?>
<h3>Select photo to pin!</h3>
<form enctype='multipart/form-data' method='post'>
<?php
if (isset($_POST['pin']) && $_POST['pin'] == 'upload') {
$location = $_POST['location'];
$bid= $_POST['bid'];
$desc = $_POST['desc'];
$file = $_FILES['filename']['name'];
$file_type = $_FILES['filename']['type'];
$file_size = $_FILES['filename']['size'];
$file_tmp = $_FILES['filename']['tmp_name'];
if (empty($desc) or empty($file)) {
echo "Please fill all the fields! <br /><br />";
} else {
switch ($file_type) {
case 'image/jpeg': $ext = '.jpg'; break;
case 'image/gif': $ext = '.gif'; break;
case 'image/png': $ext = '.png'; break;
case 'image/tiff': $ext = '.tif'; break;
default: $ext = ''; break;
}
if ($ext) {
$url = 'img/'.$desc.$ext;
move_uploaded_file($file_tmp, 'img/'.$desc.$ext);
if ($conn->connect_error) die("Couldn't connect to database!".$conn->connect_error);
$insert = "insert into pins(bid, url, time) values('$bid', '$url', '$location', now())";
$result = $conn->query($insert);
if(!$result) {
die ($conn->error);
} else {
echo "Photo Uploaded!";
}
}
}
} elseif (isset($_POST['pin']) && $_POST['pin'] == 'download') {
$location = $_POST['location'];
$bid= $_POST['bid'];
$url = $_POST['url'];
$name = basename($url);
$locurl = "img/$name";
$result = file_put_contents($locurl, file_get_contents($url));
if ($result) {
$insert = "insert into pins(bid, url, location, time) values('$bid', '$locurl', '$location', now())";
$result = $conn->query($insert);
if(!$result) {
die ($conn->error);
} else {
echo "Successfully pin from Internet!";
}
}
}
?>
<br />
Currently Location: <span><input type='text' name='location' /></span>
<br />
Description: <br />
<input type='text' name='desc' />
<br /><br />
Select board: <br />
<select name='bid'>
<?php
$uid = $_GET['uid'];
$query = "select bid ,board_name from pinboards where uid = '$uid'";
$result = $conn->query($query);
while ($run = $result->fetch_array()) {
$bid = $run['bid'];
$boardname = $run['board_name'];
echo "<option value='$bid'>$boardname</option>";
}
?>
</select>
<br /><br />
Select Photo: <br />
<input type='file' name='filename' />
<br /><br />
<input type='submit' name='pin' value='upload' />
<br /><br />
Pin through url:
<br /><br />
Input the url to pin: <br /><br />
<input type='url' name='url' /> <br /><br />
<input type='submit' name='pin' value='download' />
</form>
</div>
</body>
</html>