/    Sign up×
Community /Pin to ProfileBookmark

Listing folder and insert to mysql

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(“[/.]”, $filename) ;
$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 ?????

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@iotaFeb 23.2008 — if $current == $last , don't insert/repeat the last file on the database.
×

Success!

Help @euqrop spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...