1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| <?php
// This function reads all available news
function getNewsList(){
$fileList = array();
// Open the actual directory
if ($handle = opendir("news"))
{
// Read all file from the actual directory
while ($file = readdir($handle))
{
if (!is_dir($file) && substr($file,-3) == 'txt')
{
$fileList[] = $file;
}
}
}
rsort($fileList);
return $fileList;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Suppression news</title>
<script type="text/javascript"
src="jquery/jquery-1.7.1.min.js"></script>
</head>
<body>
<pre>
<?php
print_r(getNewsList());
?>
</pre>
<?php echo '<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("#delete").click(function(event){
$.get(
"delete.php?file='.$news.'",
callback);
});
});
</script>';
?>
<table>
<tr><td width="20%">Fichier</td><td width="70%">Description</td><td width="10%">Supprimer</td></tr>
<?php
foreach (getNewsList() as $news)
{
echo '<tr><td>'.$news.'</td><td>'. substr(file_get_contents('news/'.$news),0,50).'...</td><td><form><input value="X" type="button" id="delete" onclick="return confirm(\'Voulez-vous vraiment supprimer '.$news.' ?\')"></form></td></tr>';
}
?>
</table>
</body>
</html> |