0

我对 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();
}
4

1 回答 1

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();
}
于 2013-05-02T13:04:31.587 回答