Zubrag.com
September 25, 2018, 07:24:03 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Php view and delete files  (Read 2892 times)
poshdosh
Newbie
*
Posts: 6


« on: May 21, 2012, 04:06:07 PM »


Hi all

I've been writing a script to view all the files in a dir
It also has a form which you need to be able to then delete one of the files.
Here is my code so far:


<!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>
<title>Manage</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
</head>
<body>
<?php

if ($handle = opendir('img/')) {
    echo "Files:\n";

    /* This is the correct way to loop over the directory. */
    while (false !== ($entry = readdir($handle))) {
        echo "$entry\n";
    }

    closedir($handle);
}
?>
<center>
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post"
enctype="multipart/form-data">
Filename: <input type="text" name="file"
<br />
<input type="submit" name="Submit" value="Submit" />
</form>
<?php
$DelFilePath = $setup["$file"] . $fileName;
 
# delete file if exists
if (file_exists($DelFilePath)) { unlink ($DelFilePath); }
?>
</body>
</html>

Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC