Start a conversation

Text Import

We can also use the code to perform the import other file types.
For example import the tables and data from a text file (txt).

First we should create two applications of the type Blank, let's call them blank and blank_2.

In the event of OnExecute blank application, put the following code:

<form style='margin-top:50px;' action="../blank_2/blank_2.php" method="POST" enctype="multipart/form-data">
            <p><label for="Send file">Send file:</label></p>
            <input type="file" name="file" class="width233" />
            <input type="submit" name="send" value="Send" />

We can see the action directed to the blank_2 application.

In the event OnExecute of blank_2 application put the code below:

$file = $_FILES['file'];
$file = file($file['tmp_name']);
$file_name = explode(".",$file['name']);

    foreach ($file as $line_num => $line) {
            $columns = str_replace(" "," varchar(255),",$line);
            sc_exec_sql("CREATE TABLE IF NOT EXISTS ".$file_name[0]." (".$columns." varchar(225) )","conn_mysql");
            $columns = str_replace(" ",",",$line);
            $date = str_replace(" ","','",$line);
            sc_exec_sql("INSERT INTO ".$file_name[0]." ( ".$columns.") values ( '".$date."')","conn_mysql");
    sc_lookup(ds,"SELECT COUNT(*) FROM ".$file_name[0],"conn_mysql");
        sc_alert("Inserted records successfully!");

When performing the blank can view the following screen:

When entering a file:

And when we click on send:


Model for sending text file:

First line: Name of the columns, followed by a space.

Second line onwards: Values column.


   Id Name Passowrd

   1 Netmake Netmake

   2 Netmake Netmake


Choose files or drag and drop files
Was this article helpful?
  1. Ronyan Alves

  2. Posted
  3. Updated


  1. Seta Sistemas

    Valeu, muito bom