JREAM Posted September 7, 2008 Share Posted September 7, 2008 in the first TD on the print part, how would i make the option to unlink the file? do i need to create a function? if so, how do i get the right filename inside the while loop for the function? while ($file = readdir($dir_handle)) { if ($file != '.' && $file != '..') { print '<tr> <td><a href="?action=delete">Delete</a></td> <td class="shade2"><strong><a href="../../../images/'.$file.'" target="_blank">'.$file.'</strong></td> <td class="shade2"><input size="40" type="text" value="../../../images/'.$file.'"></td> </tr> '; } } Link to comment https://forums.phpfreaks.com/topic/123092-unlink/ Share on other sites More sharing options...
adam291086 Posted September 7, 2008 Share Posted September 7, 2008 you coul create a switch statement. Withing your link for the file have a comman part. Then if comman = delete then run this function delete. good php switch statements and see what you get. Link to comment https://forums.phpfreaks.com/topic/123092-unlink/#findComment-635697 Share on other sites More sharing options...
Fadion Posted September 7, 2008 Share Posted September 7, 2008 <?php if(isset($_GET['action']) and $_GET['action'] == 'delete'){ $file = $_GET['file']; if(file_exists($file)){ unlink($file); } else{ echo "File doesn't exist."; } } while ($file = readdir($dir_handle)) { if($file != '.' && $file != '..') { print '<tr> <td><a href="?action=delete&file='. $file . '">Delete[/url]</td> <td class="shade2"><strong><a href="../../../images/'.$file.'" target="_blank">'.$file.'</strong></td> <td class="shade2"><input size="40" type="text" value="../../../images/'.$file.'"></td> </tr> '; } } ?> Link to comment https://forums.phpfreaks.com/topic/123092-unlink/#findComment-635707 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.