我对 php 还是很陌生,但基本上我要做的是传递上传的文件的名称,以便可以将其与相应的表单信息一起输入数据库。
// uploading file
if ($_FILES){
print_r($_FILES);
mkdir ($dirname, 0777, true);
move_uploaded_file($_FILES["file"]["tmp_name"],$dirname."/".$_FILES["file"]["name"]);
}
// Form Processing
if($_POST['formSubmit'] == "Submit")
{
$varName = $_POST['formName'];
$varLat = $_POST['formLat'];
$varLong = $_POST['formLong'];
$varPic = $_FILES["file"]["name"];
$db = mysql_connect($dbhost,$dbuser,$dbpass);
if(!$db) die("Error connecting to MySQL database.");
mysql_select_db($dbname ,$db);
$sql = "INSERT INTO new_submissions (locationName, latitude, longitude, picture) VALUES (".
PrepSQL($varName) . ", " .
PrepSQL($varLat) . ", " .
PrepSQL($varLong) . ", " .
PrepSQL($varPic) . ")";
mysql_query($sql);
header("Location: thankyou.html");
exit();
}