gpt4 book ai didi

php - 无法传递参数。添加图像根名称$_Files以插入到数据库

转载 作者:行者123 更新时间:2023-11-29 12:31:09 28 4
gpt4 key购买 nike

我在将上传文件的文件根添加到我的数据库时遇到问题。我被告知尝试下面的操作,但我收到错误并且不再收到回复:无法在 send_config.php 中通过引用传递参数 8第 47 行是以下行。 '".$target_file."');

<小时/>

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;
};
<小时/>

电子邮件.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>';
}
}

最佳答案

您只需添加 $target_file 作为参数,而不是像字符串一样。当你悲伤sssssss时,你指定这是一个字符串。试试这个:

$stmt->bind_param('sssssss', $_REQUEST['company_name'], $_REQUEST['ref'], $_REQUEST['website'], $_REQUEST['email'], $_REQUEST['tel'], $_REQUEST['message'], $target_file);

关于php - 无法传递参数。添加图像根名称$_Files以插入到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27481123/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com