我无法将上传文件的文件根添加到我的数据库中。我被告知尝试以下以下但我得到错误,不再得到答复:无法通过send_config.php中的引用传递参数8 第47行是以下行。 '" $ TARGET_FILE"&#39);
send_config.php
$stmt = $conn->prepare("INSERT INTO detail (company_name,ref,website,email,tel,message,location) VALUES (?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param('sssssss',
$_REQUEST['company_name'],
$_REQUEST['ref'],
$_REQUEST['website'],
$_REQUEST['email'],
$_REQUEST['tel'],
$_REQUEST['message'],
'".$target_file."');
include 'mail2.php';
if($stmt->execute()) {
echo "Database Successfully Updated.";
} else {
echo "Error To Update Database: " . $stmt->error;
};
email.php
$to = 'test@gmail.com';
$subject = 'Website Submission';
$company_name = $_POST['company_name'];
$ref = $_POST['ref'];
$website = $_POST['website'];
$email = $_POST['email'];
$tel = $_POST['tel'];
$message = $_POST['message'];
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "<p>File is an image - " . $check["mime"] . ".</p>";
$uploadOk = 1;
} else {
echo '<p style="color:red;">File is not an image.</p>';
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo '<p style="color:red;">Sorry, file already exists.</p>';
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo '<p style="color:red;">Sorry, your file is too large.</p>';
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo '<p style="color:red;">Sorry, only JPG, JPEG, PNG & GIF files are allowed.</p>';
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo '<p style="color:red;">Sorry, your file was not uploaded.</p>';
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo '<p style="color:red;">Sorry, there was an error uploading your file.</p>';
}
}
答案 0 :(得分:1)
您只需添加$target_file
作为参数,而不是字符串。你伤心sssssss
时指定的是一个字符串。试试这个:
$stmt->bind_param('sssssss', $_REQUEST['company_name'], $_REQUEST['ref'], $_REQUEST['website'], $_REQUEST['email'], $_REQUEST['tel'], $_REQUEST['message'], $target_file);