Jest to w miarę prosty skrypt usuwania plików z folderu przy pomocy AJAXA.
Kod
HTML File:
Code:
<html>
<head>
<script type="text/javascript">
function deleteFileAjax(filename) {
scriptitem = document.createElement('script');
scriptitem.type = 'text/javascript';
scriptitem.src = 'ajax.php?filename=' + filename;
scriptitem.id = 'ajax';
document.body.appendChild(scriptitem);
setTimeout('document.body.removeChild(document.getElementById("ajax"))', 500);
}
</script>
</head>
<body>
<a href="java script:deleteFileAjax('log.txt');">Delete</a>
</body>
</html>
Ajax.php
Code: [Select]
<?php
if (isset($_GET['filename'])) {
if (unlink(htmlentities($_GET['filename']))) {
echo "alert('Great success!');";
}
}
?>
Code:
<html>
<head>
<script type="text/javascript">
function deleteFileAjax(filename) {
scriptitem = document.createElement('script');
scriptitem.type = 'text/javascript';
scriptitem.src = 'ajax.php?filename=' + filename;
scriptitem.id = 'ajax';
document.body.appendChild(scriptitem);
setTimeout('document.body.removeChild(document.getElementById("ajax"))', 500);
}
</script>
</head>
<body>
<a href="java script:deleteFileAjax('log.txt');">Delete</a>
</body>
</html>
Ajax.php
Code: [Select]
<?php
if (isset($_GET['filename'])) {
if (unlink(htmlentities($_GET['filename']))) {
echo "alert('Great success!');";
}
}
?>
Przykład tej funkcji jest na stronie
http://www.phpfreaks.com/forums/index.php?topic=159544.0
I mam teraz prośbę dla Forumowiczów ,czy aby ten skrypt jest poprawny,czy Ktoś mógłby to sprawdzić
