this is my code:
manage_files.php
<head>
<script language="JavaScript">
<!--
function Confirm_Delete() {
if (confirm("Czy jesteœ pewien, ¿e chcesz wymazaæ ten plik?")) {
return true;
} else {
return false;
}
}
//-->
</script>
</head>
<?
$table_artykuly="artykuly".$id;
//////////////////////////////////////////////////mysql//////////////////////////////////////////////////////////////
include("dla_pracownikow/dane_osobowe/formularz/danemysql.php");
// Connecting to the Database
$connect = @mysql_connect($host, $user, $pass) or die("could not connect to server");
// Selecting the Database for use
$db_select = @mysql_select_db($database) or die("could not select the database");
/////////////////////////////////////////////////tabela plikow//////////////////////////////////////////////////
$path='dla_pracownikow/artykuly_pracownikow/'.$id;
if ($handle = opendir($path)) {
echo "$handle\n";
echo "Files:\n";
/* Licznik do wierszy. */
$count=0;
?>
<table width="750" border="0" cellspacing="0" cellpadding="0" bgcolor="#CCCCCC">
<tr>
<td width="20"></td>
<td width="200"><b>nazwa wyœwietlana</b></td>
<td width="150"><b>nazwa pliku</b></td>
<td width="20"> </td>
<td width=""><b>data utworzenia</b></td>
<td width=""><b>data ostatniego odczytu</b></td>
<td width=""> </td>
<td width=""> </td>
<td width=""> </td>
<td width=""> </td>
</tr>
<? / This is the correct way to loop over the directory. /
while (false !== ($file = readdir($handle))) {
?>
<tr>
<td width="20"><?$count++; if ($count>2) {echo ($count-2);};?></td>
<form method="post" action="?pd=otworz">
<input type="hidden" name="login" value="<?echo $POST["login"];?>">
<input type="hidden" name="haslo" value="<?echo $POST["haslo"];?>">
<input type="hidden" name="numer" value="<?echo $count;?>">
<td width="200">
<?
/////////////////////////////////////////wywo³anie mysql//////////////////////////////////////////////
$SQL = "SELECT * FROM $table_artykuly where nazwa_plik='$file'";
$result = @($SQL) or die("could not complete your query");
$row = @mysql_fetch_array($result);
if (isset($POST["numer"])){
if ($count==$POST["numer"]&&isset($_POST["plik_edycja"])){
?><input type="text" name="tytul_plik" value="<?echo $row["tytul_plik"];?>">
<?;}else{echo $row["tytul_plik"];};}
else{echo $row["tytul_plik"];};?>
<input type="hidden" name="plik_file" value="<?echo "$file";?>">
<? if (isset($POST["ok"])&&(isset($POST["tytul_plik"]))){
$sql="update $table_artykuly
set
tytul_plik = '$POST[tytul_plik]'
where nazwa_plik='$POST[plik_file]'";
$result=@( $sql);};
if (isset($POST["plik_kasuj"])){
$sql = "DELETE FROM $table_artykuly where nazwa_plik='$POST[plik_file]'";
$result=@( $sql);};
/////////////////////////////////////////////////////koniec wywo³ania mysql///////////////////////////////
?>
</td>
<td width="150"><?
//////////////////////////////////////////////////////////filesystem//////////////////////////////////////
if ($count>2)
{echo "$file\n";
if (isset($POST["numer"])){
if (($count==$POST["numer"])&&(isset($_POST["plik_kasuj"]))){
unlink($path."/".$file);};};
};
///////////////////////////////////////////////////////endoffilesystem////////////////////////////////////////
?></td>
<td width="20" align="right">
<? if ($count>2) {echo round((filesize($path."/".$file)/1024))."KB";};?>
</td>
<td><? if ($count>2) {echo date("F j Y h:i:s A", filemtime($path."/".$file));};?></td>
<td><?if ($count>2) {echo date("F j Y h:i:s A", fileatime($path."/".$file));};?></td>
<td > </td>
<td><?if (isset($_POST["numer"])) {if (($count==$_POST["numer"])&&(isset($_POST["plik_edycja"]))){?><input type="submit" name="ok" value="ok"><?;};};?></td>
<td><? if ($count>2) {?><input type="submit" name="plik_edycja" value="edycja"><?;};?></td>
<td><? if ($count>2) {?>
<input type="submit" name="plik_kasuj" value="kasuj" OnClick="return Confirm_Delete()">
<?;};?></td>
</form>
</tr>
<?}
closedir($handle);
mysql_close($connect);
}
?>
</table>
completly don't know if it is readible
/////////////////////////////////////////////////////////////////////////////////
file "danemysql.php" only has variables which describe password, table and so on ($host, $user, $pass and $database).
///////////////////////////////////////////////////////////////////////////////
small language explanation
Polish - English
ok=ok
edytuj=edit
kasuj=delete
Czy jesteœ pewien, ¿e chcesz wymazaæ ten plik? - Are you sure you want do delete this file;
plik=file
plik_kasuj means delete_file