gpt4 book ai didi

php - 图片上传php mysql

转载 作者:行者123 更新时间:2023-11-29 21:11:24 25 4
gpt4 key购买 nike

我正在尝试上传 2 个图像并将每个文件的文件名保存到 MySQL 数据库。我尝试了不同的选择,但我无法让它发挥作用。

在我的 MYSQL 表中文件名的字段名称称为 file_namevarchar 500

我可以毫无问题地将其他表单数据保存到我的数据库中。但是我无法上传图像。

以下是我的网络表单的图像部分。

这里是 FORM 操作区域

<form method="post" action="php/smartprocess.php" enctype="multipart/form-data" id="smart-form">

我的图片上传部分如下

smartprocess.php 部分是

 <?php 

if (!isset($_SESSION)) session_start();
if(!$_POST) exit;

require 'database.php';

include dirname(__FILE__).'/settings/settings.php';
include dirname(__FILE__).'/functions/emailValidation.php';

$TechName = strip_tags(trim($_POST["TechName"]));
$FullAssembly = strip_tags(trim($_POST["FullAssembly"]));
$Notes = strip_tags(trim($_POST["Notes"]));
$SignedDate = strip_tags(trim($_POST["SignedDate"]));
$captcha = strip_tags(trim($_POST["captcha"]));




try {

$q = "INSERT INTO tportal (TechName, FullAssembly, Notes, SignedDate)

VALUES (:TechName, :FullAssembly, :Notes, :SignedDate)";


$query = $conn -> prepare($q);

$results = $query -> execute(array(

":TechName" => $TechName,
":FullAssembly" => $FullAssembly,

":Notes" => $Notes,
":SignedDate" => $SignedDate,

));

if ($conn->query($q)) {

$errors = array();

echo '<div class="alert notification alert-success">Problem has accured please try again.</div>';
//Javascript alert top
/*echo "<script type= 'text/javascript'>alert('Issue adding data');</script>";*/

}
else{
echo '<div class="alert notification alert-success">Your message has been sent successfully!</div>';
//Javascript alert top
/*echo "<script type= 'text/javascript'>alert('Data not successfully Inserted. $PocketCond');</script>";*/

}

$conn = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}


?>
<?php

if(isset($_POST["captcha"])){
if (!$captcha) {
$errors[] = "You must enter the captcha code";
} else if (($captcha) != $_SESSION['gfm_captcha']) {
$errors[] = "Captcha code is incorrect";
}
}

?>



<div class="section">
<label for="file1" class="field-label">
Upload another image - <span class="small-text fine-grey"> (ONLY JPG : PNG : PDF) </span>
</label>
<label class="field prepend-icon file">
<span class="button btn-primary"> Choose File </span>
<input type="file" class="gui-file" name="image" id="file1"
onChange="document.getElementById('uploader1').value = this.value;">
<input type="text" class="gui-input" id="uploader1" placeholder="no file selected" readonly>
<span class="field-icon"><i class="fa fa-upload"></i></span>
</label>
</div><!-- end section -->

非常感谢您的帮助和时间。此致,

最佳答案

使用php的$_FILES变量来帮助您上传文件。 php中有一个关于文件上传的简单教程here

关于php - 图片上传php mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36335627/

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