Hi i have a little program that reads the content of a folder , extracts the extension, the size of the file, and saves it in the database as well as another information that i insert in the script. My problem is that he repeats the last file on the database.
Mysql5 table is innodb and php5.
<?php
function findexts ($filename)
{
$filename = strtolower($filename) ;
$exts = split(“[/
$n = count($exts)-1;
$exts = $exts[$n];
return $exts;
}
$thelist = array();
$dir = ‘../doc/folhetos/’;
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != “.” && $file != “..”) {
$treta=$file;
$ext=findexts ($treta) ;
$tip=’Folhetos’;
$file = $dir.$file;
$size=filesize($file);
$thelist[] = array(‘file’ => $file,’tipo’ => $tip,’treta’ => $treta ,’filesize’ => filesize($file));
mysql_query(“INSERT INTO doc (file,way,size,tipo,ext) VALUES (‘$treta’,’$file’,’$size’,’$tip’,’$ext’)”);
}
}
closedir($handle);
}
?>
And then display:
</p>
<table border=”1″ bordercolor=”#000000″>
<tr>
<td width=”40″><strong>Nome</strong></td>
<td width=”62″><div align=”center”><strong>Tamanho</strong></div></td>
<td width=”33″><div align=”center”><strong>Tipo</strong></div></td>
</tr>
<?php
for($i = 0; $i < count($thelist); $i++) {
?>
<tr>
<td><a href=”<?=$thelist[$i][‘file’]?>”><?=$thelist[$i][‘treta’]?></a></td>
<td colspan=”4″><?=round(($thelist[$i][‘filesize’]/1024000),3);?> Mb</td>
<td width=”20″><?=$thelist[$i][‘tipo’]?></td>
</tr>
<?php
}
?>
<?php
for($i = 0; $i < count($thelista); $i++) {
?>
<tr>
<td><a href=”<?=$thelista[$i][‘file’]?>”><?=$thelista[$i][‘treta’]?></a></td>
<td colspan=”4″><?=round(($thelista[$i][‘filesize’]/1024000),3);?> Mb</td>
<td><?=$thelista[$i][‘tipo’]?></td>
</tr>
<?php
}
?>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
Can anyone help ?????