[thelist] refresh after unlink function

Mark Mckee lists at soddengecko.com
Wed Jan 17 14:39:04 CST 2007


hi all

i am almost done creating the script to delete text files from the 
server. i have iot working a treat, however, after i click delete, the 
file is removed but the page still displays the file and it does not 
refresh. i have tried using a header function to refresh but i get the 
cannot modify headers error and the page does not refresh at all.

here is the code

<?php



    function file_type($file){
        $path_chunks = explode("/", $file);
        $thefile = $path_chunks[count($path_chunks) - 1];
        $dotpos = strrpos($thefile, ".");
        return strtolower(substr($thefile, $dotpos + 1));
    }
    $path = "files/";
    $file_types = array('', 'txt', 'html');
    $p = opendir($path);
        while (false !== ($filename = readdir($p))) {
            $files[] = $filename;
        }
    sort($files);
        foreach ($files as $file) {
            $extension = file_type($file);
            if($file != '.' && $file != '..' && array_search($extension, 
$file_types)){
                $file_count++;



?>

<h2> <?=$file?></h2>
(
<a href="<?=$path.$file?>" target="_blank">View[/url] |
<a href="">Edit[/url] |
<a href="?file=<?=urlencode($path.$file)?>">Delete[/url] |
<a href="">Upload[/url])



<?php @unlink(urldecode($_GET[file]));
header('Location: ' . $_SERVER['PHP_SELF']);?>

<?
            }
        }
?>


can anyone shed light on that for me, i am struggling and google and 
php.net are turning up nothing useful


mark m....






More information about the thelist mailing list