如何添加标题,描述和&关键词形式到此?

时间:2017-09-30 01:57:53

标签: php mysql

您好我想知道如何添加说明,标题和&我的文件上传脚本的关键字?我已经将文件上传工作了。

所以我希望人们能够输入标题和描述以及关键字并将其保存到数据库中。

P.S:我已经有文件上传系统了。用户上传文件将其保存到临时文件夹并将其上传到数据库,这样您就不需要添加文件上传部分,只需添加标题,关键字和&描述

文件上传脚本 这允许文件上传。

    <?php
<?php 
include_once 'dbconnect.php';

// fetch files
$sql = "select filename from tbl_files";
$result = mysqli_query($con, $sql);
?>
<?php
session_start();
include_once "vendor/autoload.php";
$page = new membership\Page(1);
if ($page->isValid() == true) {
    ?>

    <center>
        <div class='container'>
            <div class='row'>
                <div class='col-xs-8 col-xs-offset-2 well'>
                    <form action='upload.php' method='post' enctype='multipart/form-data'>
                        <legend>Select File to Upload:</legend>
                        <div class='form-group'>
<input type='textname' name='title' />
<input type='textname' name='desc' />
                            <input type='file' name='file1' />
                        </div>
                        <div class='form-group'>
                            <input type='submit' name='submit' value='Upload' class='btn btn-info'/>
                        </div>
                        <?php if (isset($_GET['st'])) { ?>
                            <div class='alert alert-danger text-center'>
                                <?php
                                if ($_GET['st'] == "success") {
                                    echo "File Uploaded Successfully!";
                                } else {
                                    echo 'Invalid File Extension!';
                                }
                                ?>
                            </div>
                        <?php } ?>
                    </form></div></div></center>

<?php } ?>

upload.php的: 这是控制文件上载的文件。

    <?php include('dbconnect.php'); ?>
<?php
//check if form is submitted
if (isset($_POST['submit']))
{
    $filename = $_FILES['file1']['name'];

    //upload file
    if($filename != '')
    {
        $ext = pathinfo($filename, PATHINFO_EXTENSION);
        $allowed = ['zip', 'rar', 'php', 'html', 'sql'];

        //check if file type is valid
        if (in_array($ext, $allowed))
        {
            // get last record id
            $sql = 'select max(id) as id from tbl_files';
            $result = mysqli_query($con, $sql);
            if (count($result) > 0)
            {
                $row = mysqli_fetch_array($result);
                $filename = ($row['id']+1) . '-' . $filename;
            }
            else
                $filename = '1' . '-' . $filename;

            //set target directory
            $path = 'uploads/';

            $created = @date('Y-m-d H:i:s');
            move_uploaded_file($_FILES['file1']['tmp_name'],($path . $filename));

            // insert file details into database
            $sql = "INSERT INTO tbl_files(filename, created) VALUES('$filename', '$created')";
            mysqli_query($con, $sql);
            header("Location: new-project.html?st=success");
        }
        else
        {
            header("Location: new-project.html?st=error");
        }
    }
    else
        header("Location: new-project.html");
}
?>

MySQL的:

    CREATE TABLE IF NOT EXISTS `tbl_files` (
  `id` int(9) NOT NULL AUTO_INCREMENT,
  `filename` varchar(255) NOT NULL,
  `created` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

另外,我需要帮助为关键字,标题和&amp;创建表格。描述

编辑 ::所以我把所有东西都搞定了但是现在我无法在页面上显示它只是空白的标题。无论如何这里是项目显示的代码:

    <?php
    include_once 'dbconnect.php';

    // fetch files
    $sql = "select filename from tbl_files";
    $result = mysqli_query($con, $sql);
    ?>
    <div class="gboxtop"></div>

    <div div="button-pro">
    <button><a href="new-project.html">New Project</a></button>
    </div>
      <div class="left">
        <div class="left_articles">

          <h2><a href="#">Lastest Projects</a></h2>

    <div class="row">
            <div class="col-xs-8 col-xs-offset-2">
    <table class="table table-striped table-hover">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>File Name</th>
                            <th>View</th>
                            <th>Download</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php
                    $i = 1;
                    while($row = mysqli_fetch_array($result)) { ?>
                    <tr>
                        <td><?php echo $i++; ?></td>
                        <td><?php echo $row['title']; ?></td>
                        <td><a href="uploads/<?php echo $row['filename']; ?>" target="_blank">View</a></td>
                        <td><a href="uploads/<?php echo $row['filename']; ?>" download>Download</td>
                    </tr>
                    <?php } ?>
                    </tbody>
                </table>
    </div></div></div>
</div></div></div></div>

//Start Table Style  
    <style>table.blueTable {
      border: 1px solid #1C6EA4;
      background-color: #EEEEEE;
      width: 100%;
      text-align: left;
      border-collapse: collapse;
    }
    table.blueTable td, table.blueTable th {
      border: 1px solid #AAAAAA;
      padding: 3px 2px;
    }
    table.blueTable tbody td {
      font-size: 13px;
    }
    table.blueTable tr:nth-child(even) {
      background: #D0E4F5;
    }
    table.blueTable thead {
      background: #1C6EA4;
      background: -moz-linear-gradient(top, #5592bb 0%, #327cad 66%, #1C6EA4 100%);
      background: -webkit-linear-gradient(top, #5592bb 0%, #327cad 66%, #1C6EA4 100%);
      background: linear-gradient(to bottom, #5592bb 0%, #327cad 66%, #1C6EA4 100%);
      border-bottom: 2px solid #444444;
    }
    table.blueTable thead th {
      font-size: 15px;
      font-weight: bold;
      color: #FFFFFF;
      border-left: 2px solid #D0E4F5;
    }
    table.blueTable thead th:first-child {
      border-left: none;
    }

    table.blueTable tfoot {
      font-size: 14px;
      font-weight: bold;
      color: #FFFFFF;
      background: #D0E4F5;
    }
    .button-pro {
    float: right;
    }
    </style>

1 个答案:

答案 0 :(得分:2)

运行:

ALTER TABLE tbl_files ADD title VARCHAR(255) AFTER created;

编辑:

<input type='text' name='title' maxlength="255"/>

在//将文件详细信息插入数据库之前添加:

$title = '';
if(!empty($_POST['title']))
{
   $title = mysqli_real_escape_string($con, $_POST['title']);
}

编辑:

$sql = "INSERT INTO tbl_files(filename, created, title) VALUES('$filename', '$created', '$title')";

其余的类比