doudu5498 2018-10-01 02:55
浏览 203

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

It's me again. I have a problem in inserting the name of the uploaded file on the database. I've successfully uploaded the file and the file has been moved to the dir that I want, can anyone help me to figure it out what's wrong in my code? Also, I've tried putting some echo on it and I got "not success", and make the database value nullable. here's my code.

  <?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");

?>
  • 写回答

1条回答 默认 最新

  • doutang1946 2018-10-01 03:28
    关注

    do it like this.

    change this

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

    to

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配