我仍然是相当新的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();
}
答案 0 :(得分:0)
把这个
// 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")
{
if ($_FILES){
print_r($_FILES);
mkdir ($dirname, 0777, true);
move_uploaded_file($_FILES["file"]["tmp_name"],$dirname."/".$_FILES["file"]["name"]);
}
$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();
}