Skip to content

Instantly share code, notes, and snippets.

@henryyang42
Created May 8, 2014 15:50
Show Gist options
  • Save henryyang42/dd3949fe6209b1a9c4c3 to your computer and use it in GitHub Desktop.
Save henryyang42/dd3949fe6209b1a9c4c3 to your computer and use it in GitHub Desktop.
<?php
$db_server = "localhost";
$db_user = "henryyang42";
$db_passwd = "gg";
$db_name = "henryyang42";
if(!@mysql_connect($db_server, $db_user, $db_passwd)){
die("無法對資料庫連線");
}
mysql_query("SET NAMES utf8");
if(!@mysql_select_db($db_name)){
die("無法使用資料庫");
}
?>
<?php
echo "start<br>";
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 10240000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
$des = $_POST['des'];
$lng = $_POST['lng'];
$lat = $_POST['lat'];
$sql = "INSERT INTO picture (decription, lat, lng) VALUES ('$des', '$lat', '$lng')";
mysql_query($sql);
echo "<br> $sql";
$sql = "SELECT * from picture ORDER BY pictureID DESC LIMIT 1";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
echo $row['pictureID'];
$filename = $row['pictureID'];
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $filename);
echo "Stored in: " . "upload/" . $filename;
}
}
else
{
echo "Invalid file";
}
echo '<meta http-equiv=REFRESH CONTENT=0;url=google_map.php>';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment