上传带有日期的文件

时间:2017-05-22 07:48:57

标签: php mysql date

我有一个页面将文件上传到我的数据库,我试图记录文件上传的那一天,所以我可以检查并查看到我的表,但每次我上传文件,它都不记录任何日期

<?php

function upload_image()
{
    if ( isset($_FILES["user_image"]) )
    {
        $date = date('M-D-Y');
        $destination = './upload/' . $_FILES['user_image']['name'];
        move_uploaded_file($_FILES['user_image']['tmp_name'], $destination);
        return $_FILES['user_image']['name'];
    }
}

function get_image_name($user_id)
{
    include('db3.php');
    $statement = $connection->prepare("SELECT image FROM users1 WHERE id = '$user_id'");
    $statement->execute();
    $result = $statement->fetchAll();
    foreach($result as $row)
    {
        return $row["image"];
    }
}
function get_total_all_records()
{
    include('db3.php');
    $statement = $connection->prepare("SELECT * FROM users1");
    $statement->execute();
    $result = $statement->fetchAll();
    return $statement->rowCount();
}

?>

我的插入查询:

<?php
include('db3.php');
include('function.php');
if(isset($_POST["operation"]))
{
    if($_POST["operation"] == "Add")
    {
        $image = '';
        if($_FILES["user_image"]["name"] != '')
        {
            $image = upload_image();
        }
        $statement = $connection->prepare("
            INSERT INTO users1 (memorandum, titlee, image, date)
            VALUES (:memorandum, :titlee, :image, date)
        ");
        $result = $statement->execute(
            array(
                ':memorandum'   =>  $_POST["memorandum"],
                ':date' =>  $_POST["date"],
                ':titlee'   =>  $_POST["titlee"],
                ':image'        =>  $image
            )
        );
        if(!empty($result))
        {
            echo 'Data Inserted';
        }
    }
    if($_POST["operation"] == "Edit")
    {
        $image = '';
        if($_FILES["user_image"]["name"] != '')
        {
            $image = upload_image();
        }
        else
        {
            $image = $_POST["hidden_user_image"];
        }
        $statement = $connection->prepare(
            "UPDATE users1
            SET memorandum = :memorandum, titlee = :titlee, image = :image , date = :date ,
            WHERE id = :id
            "
        );
        $result = $statement->execute(
            array(
                ':memorandum'   =>  $_POST["memorandum"],
                ':titlee'   =>  $_POST["titlee"],
                ':date' =>  $_POST["date"],
                ':image'        =>  $image,
                ':id'           =>  $_POST["user_id"]
            )
        );
        if(!empty($result))
        {
            echo 'Data Updated';
        }
    }
}

?>

0 个答案:

没有答案