Hello,
On the following link you can download the video from the webinar today about XLS, CSV and Access Importation with txt file reading:
During the example we used two blanks to make the .txt file reading and import the files manually:
Blank 1:
?>
<center>
<form style=‘margin-top:50px;’ action="…/blank_2/blank_2.php" method=“POST” enctype=“multipart/form-data”>
<fieldset>
<p><label for=“Enviar arquivo”>Send File:</label></p>
<input type=“file” name=“arquivo” class=“width233” />
<input type=“submit” name=“enviar” value=“Enviar” />
</fieldset>
</form>
</center>
<?php
Blank 2:
$arquivo = $_FILES[‘arquivo’];
$file = file($arquivo[‘tmp_name’]);
$file_name = explode(".",$arquivo[‘name’]);
foreach ($file as $line_num => $line) {
if($line_num==0){
$colunas = str_replace(" "," varchar(255),",$line);
sc_exec_sql("CREATE TABLE IF NOT EXISTS ".$file_name[0]." (".$colunas." varchar(225) )","conn_mysql");
$colunas = str_replace(" ",",",$line);
}
if($line_num>=1){
$dados = str_replace(" ","','",$line);
sc_exec_sql("INSERT INTO ".$file_name[0]." ( ".$colunas.") values ( '".$dados."')","conn_mysql");
}
}
sc_lookup(ds,"SELECT COUNT(*) FROM ".$file_name[0],"conn_mysql");
if({ds[0][0]}>0){
sc_alert("success!");
}