【问题标题】:How to store content of text file in Database using PHP如何使用 PHP 将文本文件的内容存储在数据库中
【发布时间】:2015-04-16 19:05:40
【问题描述】:

//输出开始

输出文件:-05012015.txt

  This is of my output of file which is the mapper file used for the verification But all below no are store in the database .That No Description  are as follow


            34012015000180001000631931058620000607262Y22122014 N                   


Above All Digits- 34 :-Contant value
                  01201500018 :-record number 
                  0001000631931058620 :-Doc No
                  000607262 :-Product Code
                  Y :-status
                  22122014 :date format DD/MM/YYYY
                    :-one Blank Space
                  N :- Status
                    :-Remaining Blank Spaces

Above Description of record which store different column in the database...

//Output End

当文本文件显示内容时,包括所有no、字符、空格和其他空格的记录的内容以文件结尾,分别存储在不同的列中。

当我点击第二个提交按钮时,然后将数据存储到 Mysql 数据库中。
我想在mysql数据库中存储文本文件的所有内容,包括所有的no、字符、空格和其他空格。

PHP 和 HTML 代码:-

        Below is the my PHP with HTMl Code 

        <html>
        <style>
        span{color: #FF0000;}
        </style>
        <body>
        <script type="text/javascript">
        function validate()
        {
        if( document.myForm.photo.value == "" )
           {
             alert( "Please Upload File!" );
             document.myForm.photo.focus();
             return false;
           }
            return( true );
        }
        </script>
        <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" enctype="multipart/form-data" name="myForm" onsubmit="return(validate());">
        Attach Mapper File:-<input type="file" name="photo" size="140"> <span>[Select Only  .TXT fle]</span>&nbsp;&nbsp;&nbsp;
         <input type="submit" name="submit" value="Submit">&nbsp;&nbsp;&nbsp;
        <br ><br> <br> 

        </form>

        </body>
        </html>

        ===================================================================================================================================================
        <b>File Name:-&nbsp;&nbsp;&nbsp;<?php
        // escape variables for security
              $pic=( $_FILES['photo']['name']);
         echo basename($pic) . "<br/>";?><br> 
        File Description:-</b><br><br><br> 

        <?php

        $file=fopen ("test/$pic","r") or exit("Error");
        $data="";

        while(!feof($file))
        {

          $data .= "<pre>" . fgets($file) . "<br/>";
        }

        fclose($file);
        echo $data;

        ?>
        =====================================================================================================================================================================
        <html>
        <body>
         <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
         <input type="submit" name="submit2" value="Submit">&nbsp;&nbsp;&nbsp;
        </form>
        </body>
        </html>

//Code End

Mysql 表语法:-

CREATE TABLE test(
id int(5) NOT NULL AUTO_INCREMENT,
no1 varchar(40)  NOT NULL,
no2 varchar(40),
no3 varchar(40),
no4 varchar(40),
no5 varchar(40),
no6 varchar(40),
no7 varchar(40),
no8 varchar(40),
no9 varchar(40),
PRIMARY KEY (id))
engine=InnoDB;

【问题讨论】:

  • 使用file_get_contents从文件中获取内容。
  • 好吧,但我如何将它存储在数据库中

标签: php html mysql sql


【解决方案1】:

只需将内容存储在变量中,然后使用 MySQL 查询将其存储在数据库中。

这样做:

$content = file_get_content('Your File');
$query = "INSET INTO table (field) VALUES ('".$content."')";

让我知道以获得更多帮助!

【讨论】:

  • 低于数字显示在我的文件上方的描述,数字存储在数据库列中..并且还给你我的数据库表语法如上所以请帮助...... .... 34012015000180001000631931058620000607262Y22122014 N
猜你喜欢
  • 2010-11-07
  • 2015-04-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-23
  • 1970-01-01
相关资源
最近更新 更多