Deleting Files
Posted: Fri Feb 18, 2005 12:22 pm
Ok. I'm having problems passing information from one page to another.
I know the answer is to use a session.
This is what I have.
I’m getting all the files I have in a directory. Using the readdir() and loading it in a loop.
But I want to be able to delete a file from the directory using php. How would I do this?
on the Deletefile.php page i have
I know the answer is to use a session.
This is what I have.
I’m getting all the files I have in a directory. Using the readdir() and loading it in a loop.
But I want to be able to delete a file from the directory using php. How would I do this?
Code: Select all
<?php
$dir = "mydir/";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
echo "<a href='Deletefile.php?file=$file'>Delete File </a> <a href='$dir$file' target='_self'>filename: $file : </a>" . "<br>";
}
closedir($dh);
}
}Code: Select all
<?php
$file = $_GETї'file']
function DeletemyFile($file)
{
unlink($file)
echo "the file : $file has been delete ";
}
?>