gpt4 book ai didi

php - 上传文件,并将文件名插入数据库

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

又是我。我在数据库中插入上传文件的名称时遇到问题。我已成功上传文件,并且文件已移动到我想要的目录,任何人都可以帮助我找出代码中的问题吗?另外,我尝试在其上添加一些回显,但“不成功”,并使数据库值可为空。这是我的代码。

  <?php
session_start();
include "../../3rdparty/engine.php";
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
if ($_SESSION['daya_user'] != '') {

if ($_FILES['dokumen']['name'] != "") {
//print_r($_POST);
$path = $_FILES['dokumen']['name'];
$ext = pathinfo($path, PATHINFO_EXTENSION);
$nama_file = 'SO'.'-'.date("Ymd").'.'.$ext;
@copy($_FILES['dokumen']['tmp_name'], '../../dokumen_atk/'.$nama_file);

mysqli_query($con,"insert into tbl_atk (name_file) values ('$nama_file')");
header("location:../../index.php?mod=atk&submod=so_upload");
}
}
//header("location:../../index.php?mod=atk&submod=so_upload");

?>

最佳答案

这样做。

改变这个

$insert = $db->query("insert into tbl_atk_upload (name_file) values ('$nama_file')", 0

mysqli_query($con,"insert into tbl_atk (name_file) values ('$nama_file')");
header('location:success.php'); //redirect to your success page

Note: you need to include your db connection and call it whenever when you use query. Like the given example variable $con above and don't enclose your query to if/eslse condition cause it's a bad habit.

关于php - 上传文件,并将文件名插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52584056/

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