<?php
$bestand=$_FILES['bestand'];
$naam=$_FILES[bestand][tmp_name];
$file=file($naam);
$regels=count($file);
if(isset($_POST['tabelweergeven']) && $_POST['tabelweergeven']){
echo "<table border=1>\n";
$data=explode("\t",$file[0]);
echo "<tr>\n";
for ($b=0; $b<count($data); $b++){
$velden[]=$data[$b];
echo " <td><b>".$data[$b]."</b></td>\n";
}
echo "</tr>\n";
for($i=1; $i< $regels; $i++){
$data=explode("\t",$file[$i]);
echo "<tr>\n";
for ($b=0; $b<count($data); $b++){
$record[]=$data[$b];
echo "<td>".$data[$b]."</td>\n";
}
echo "</tr>\n";
}
echo "</table>";
}
?><br>
Splitsen met een tab<BR>
<form action='<?php echo $_SERVER['REQUEST_METHOD']; ?>' method="post" enctype="multipart/form-data">
Tabelnaam:<input name='tabel' value='tabelnaam'><BR>
Create toevoegen <input type=checkbox name=create value=ja> <BR>
tabel weergeven <input type=checkbox name=tabelweergeven value=ja checked> <BR>
bestand : <input type=file name='bestand'><BR>
<input type=submit value='Genereer'>
</form>
<?php
$tabel=$_POST['tabel'];
$regels=count($file);
$velden='';
$data=explode("\t",$file[0]);
for ($b=0; $b<count($data); $b++){
$velden.="".$data[$b].",";
}
echo "</tr>\n";
for($i=1; $i< $regels; $i++){
$data=explode("\t",$file[$i]);
$line= "insert into ".$tabel." (".$velden.") values (";
for ($b=0; $b<count($data); $b++){
$line= "".$line." '".$data[$b]."',";
}
$line= "$line);";
$lines[]=$line;
}
$create=split(",", $velden);
if($_POST['create']){
echo "
#### Maak de tabel aan<BR>
<BR>
CREATE TABLE ".$tabel." (<BR>";
for($i=0; $i< count($create)-2; $i++){
echo " ".$create[$i]." char(100) NOT NULL default '',<BR>";
}
$cijfer=count($create)-2;
echo " ".$create[$cijfer]." char(100) NOT NULL default ''<BR>";
echo ") TYPE=MyISAM;<BR>";
}
echo "### maak de records<BR>";
for($i=0; $i<count($lines); $i++){
$lines[$i]=str_replace(", );",");",$lines[$i]);
$lines[$i]=str_replace(",)",")",$lines[$i]);
echo "".$lines[$i]."<BR>";
}
if($naam){
unlink("$naam") || die ("Foute boel");
}
?>