dmikester1 Posted October 29, 2007 Share Posted October 29, 2007 I have an app that lists out the files on a server. I have a checkbox at the end of each file. You can check any number of files. Then I have a link at the top that says "delete selected files." Could someone just tell me how to write the code to delete the files in general? I'm not asking for all the exact code, just the concept. I assume I will be calling a php or javascript function with the "onclick" method. Here is the html/php line that spits a file: <div><a href="<?=$fileurl;?>" name="file<?=$i;?>" id="file<?=$i;?>" class="<?=$class;?>"<?=$thumb2;?>><img src="images/<?=$icon;?>" alt="<?=$files[$i];?>" /><strong><?=$filename;?></strong> <em><?=round(filesize($leadon.$files[$i])/1024);?>KB</em> <?=date ("M d Y h:i:s A", filemtime($leadon.$files[$i]));?><?=$thumb;?></a><span class = "c"><input type="checkbox" name="filebox<?=$i;?>" id="filebox<?=$i;?>" value="" onclick="highlightRow(this.parentNode.parentNode, this);"></span></div> Thanks Mike Quote Link to comment https://forums.phpfreaks.com/topic/75262-deleting-files-onclick/ Share on other sites More sharing options...
Azu Posted October 30, 2007 Share Posted October 30, 2007 Personally I'd rather use a normal HTML form not a javascript for something like deleting files.. you implement the general works of it in around the same way whichever way you do it though. Basically have the javascript send a request to a URL and have the file names be in the URI. Or with a normal form have them be in POST/GET. Server side, just take those file names, and use a loop or something with unlink(filename) to delete the file. Quote Link to comment https://forums.phpfreaks.com/topic/75262-deleting-files-onclick/#findComment-381514 Share on other sites More sharing options...
dmikester1 Posted November 2, 2007 Author Share Posted November 2, 2007 Can you explain to me why you would prefer to use an html form and how that would be done? Thanks Mike Quote Link to comment https://forums.phpfreaks.com/topic/75262-deleting-files-onclick/#findComment-383156 Share on other sites More sharing options...
kratsg Posted November 2, 2007 Share Posted November 2, 2007 HTML look: <form name='delete' method='post'> File1: <input type=checkbox name='file_sys[]' value='file1.ext'> File2: <input type=checkbox name='file_sys[]' value='file2.ext'> File3: <input type=checkbox name='file_sys[]' value='file3.ext'> File4: <input type=checkbox name='file_sys[]' value='file4.ext'> File5: <input type=checkbox name='file_sys[]' value='file5.ext'> File6: <input type=checkbox name='file_sys[]' value='file6.ext'> <input type='submit'><input type='reset'></form> PHP Code $file_array = $_POST['file_sys']; foreach($file_array as $filename){ unlink($filename); } Something along those lines is what you want. Quote Link to comment https://forums.phpfreaks.com/topic/75262-deleting-files-onclick/#findComment-383170 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.