I got my first study task to make a script. Task is the following: Create a webform for uploading files, after file upload they are displayed on the same page in html table. This is my very first task and my priority is just to make it work. So I created a form and function to scan upload folder for files and then put them in array. Afterwards array is used in a cucle that builds up an html table. Please help me to build correct delete button, as I just can't get it to work. My code is here:
<?php
if ($_GET['action']=='delete' && isset($_GET['file'])) {
unlink($dir.$filelist[$i]);
echo "File ".$filelist[$i]. " has been removed";
}
//table with files
echo"<table border=1 cellpading=5 cellspasing=0>
<tr><th>#</th><th>Filename</th><th>Path</th><th>File extenstion</th><TH>File Size<th>Remove file?</th></tr>";
for ($i=0; $i <count($fileslist) ; $i++) {
echo "<tr>";
echo"<td>$i</td><td>". $fileslist[$i]."</td>";
echo "<td><a href=".$dir.$fileslist[$i].">".$fileslist[$i]."</a></td>";
echo "<td>".$ext=pathinfo(($dir.$fileslist[$i]), PATHINFO_EXTENSION)."</td>";
echo "<td>".$size= filesize_get($dir.$fileslist[$i])."</td>";
echo "<td> <a href=\"upload.php?action=delete&file=".$filelist[$i].">Delete </a></td>";
echo "<tr>";
}
echo"</tabe>";
Get following errors:
Notice: Undefined index: action in D:\PHP(1)\xampp\htdocs\upload.php on line 32
Notice: Undefined variable: filelist in D:\PHP(1)\xampp\htdocs\upload.php on line 47