Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/75262-deleting-files-onclick/
Share on other sites

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.