-
Notifications
You must be signed in to change notification settings - Fork 0
/
addphoto.php
108 lines (74 loc) · 3.44 KB
/
addphoto.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
101
102
103
104
105
106
107
108
<?php
include 'connect.php';
include 'include/phpFlickr.php';
// set up flickr authentication
$f = new phpFlickr('8f318916cbe8543c9f372fea42389230', '9d6d80a01f22a3e3', false);
$f->setToken('72157632574876529-8d5398e6261ffdaa');
if (isset($_POST['id'])) { //then we have something to add to the database
//get a database connection
$dbconnection = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error.');
mysql_select_db($dbname, $dbconnection);
//get the answers safe for the db
$timestamp = time();
$name = mysql_real_escape_string($_POST['id']);
$contributor = mysql_real_escape_string($_POST['contributor']);
//upload the file, ready for flickr
if ($_FILES['uploadFile']['size'] > 0 ) {
// echo "have file";
$oldname = $_FILES['uploadFile']['name'];
$filetype = end(explode('.',$oldname));
$newname = md5(rand().$oldname).".".$filetype;
move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'], "images/".$newname);
// echo "moved ";
}
$query = "SELECT NAME, sortname, lat, lon FROM building WHERE ID = ". $name . ";";
$db = mysql_query($query);
while ($row = mysql_fetch_array($db, MYSQL_BOTH)) {
$buildingname = $row[0] ;
$lat = $row['lat'];
$lon = $row['lon'];
$sortname = $row['sortname'];
}
//upload vars
//$photo_url = "http://tektonomastics.org/images/" . $newname;
$photo_url = "images/" . $newname;
if (!$buildingname) {
$title = "(building name not given)";
} else {
$title = $buildingname;
}
$url_name = str_replace(" ", "_", $buildingname) ;
$description = $buildingname . " is listed in <a href='http://tektonomastics.org'>Tektonomastics</a>, the building names project.\n\n <a href='http://blog.tektonomastics.org'>More about the project</a>. \n<a href='http://tektonomastics.org/map/'>Add a building!</a> \n <a href='http://tektonomastics.org/name/" . $url_name . "'>See all buildings called " . $buildingname . "</a>." ; //FIXME
$tags = "tektonomastics";
//echo $photo_url;
//now upload the image to flickr
$flickrid = $f->sync_upload($photo_url, $title, $description, $tags);
// $flickrid = $f->sync_upload("images/" . $newname);
if ($flickrid == 0) {
$flickrerror = $f->getErrorMsg();
$flickrcode = $f->getErrorCode();
echo "<html><head><title>Error!</title></head><body id='addphoto'>Oops! Something went wrong. It looks like your image didn't upload. <a href='http://tektonomastics.org/contact'>Please let us know about this problem</a> by sending us the following info:<br><br>Technically speaking, the error was: <em>#" . $flickrcode . " - " . $flickrerror . "</em>. <br><br></body></html>";
} else {
//put the responses into the database
$insertquery = "INSERT INTO flickr (buildingId, flickrImage, timestamp, user) VALUES (";
$insertquery .= "'" . $name . "', ";
$insertquery .= "'" . $flickrid . "', ";
$insertquery .= "'" . $timestamp . "', ";
$insertquery .= "'" . $contributor . "'";
$insertquery .= ");";
if (!mysql_query($insertquery,$dbconnection))
{
die('Error: ' . mysql_error());
} else {
// echo "\ninserted ok\n";
}
//add geo info to the pic
$geo = $f->photos_geo_setLocation($flickrid, $lat, $lon);
$geo = $f->photos_setTags($flickrid, "tektonomastics building");
//tidy up the mysql connection
// mysql_close($dbconnection);
//header
header('Location: http://tektonomastics.org/name/' . $sortname);
}
}
?>