anthonyw17 Posted August 1, 2009 Share Posted August 1, 2009 ok so im working on a script that lists files with a checkbox next to them and you can select the files and hit a button that deletes them using the unlink function, but it doesnt seem to work for me here this what i done so far: list_files.php <?php $URL = "http://website.com"; print "<form method='post' action='delete_files.php'>"; if ($handle = opendir('/home/staticextasy/public_html')) { // echo "Directory handle: $handle\n"; echo "<h4>Files:</h4>\n"; /* This is the correct way to loop over the directory. */ while (false !== ($file = readdir($handle))) { echo "<p><input type='checkbox' name='filename' value='$file'> <a href='$URL/$file'>$file\n</a></p>"; } /* This is the WRONG way to loop over the directory. */ while ($file = readdir($handle)) { echo "<p><input type='checkbox' name='filename' value='$file'> <a href='$URL/$file'>$file\n</a></p>"; } closedir($handle); } print "<input type='submit' value='Delete'>"; ?> delete_files.php <?php $filename = $_POST['filename']; $delete = "/home/staticextasy/public_html/$filename"; chmod($delete, 0777); unlink($delete); header ('Location: http://website.com/admin/list_files.php'); ?> any ideas? Link to comment https://forums.phpfreaks.com/topic/168343-php-manage-files-in-a-directory/ Share on other sites More sharing options...
dadamssg Posted August 1, 2009 Share Posted August 1, 2009 where are you storing this script? what directory? cause if your delete_files.php script is in public_html then you don't need "home/staticextasy/public_html/" if the $filename is in the same place as delete_files.php then you don't need to change to the path Link to comment https://forums.phpfreaks.com/topic/168343-php-manage-files-in-a-directory/#findComment-888064 Share on other sites More sharing options...
anthonyw17 Posted August 1, 2009 Author Share Posted August 1, 2009 im storing the script in /home/staticextasy/public_html/admin/ but the files are in /home/staticextasy/public_html/ like it lists it alright it just doesnt delete it Link to comment https://forums.phpfreaks.com/topic/168343-php-manage-files-in-a-directory/#findComment-888084 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.