Jump to content

Simple delete file form


XeroXer

Recommended Posts

Hi there!

I ma making a simple site for a friend of mines counter-strike clan.
Verything is done from his point of view but I think that one thing is missing.
I have allowed them to upload images and insert them into members sections.
Now I also want to add so that they can delete the images.
If they upload one file named member1.gif I haven't added any option to overwrite it the next time so it displays an error.
So then they rename the image to member1-1.gif and it goes on and on.
So I want to add a delet file section.

And I though what better place to fix it than here.

The security section is already done so all I need is the delete "sequence" :).
The file will be placed in a folder named clan and then in that folder there will be a file called upload with all the images in.
I want a PHPscript that reads the content of that foler and lists it in a drop-down menu.
There you choose the filke you wish to delete and press delete (submit).
The file should then be deleted and a success message should be printed out.

If anyone can make this, has it laying around or could give me pointers so I can make it myself I would be very happy....
:)

Have a nice day all!
Link to comment
Share on other sites

  • 11 months later...
A very simple way of doing it:

[code]
<?php
if(isset($_POST['submit'])){
unlink($_POST['file']);
echo $_POST['file'].' deleted';
}
?>
<form action="<?php echo $_SERVER['phpself']; ?>" method="POST" />
<?php
echo '<select name="file">';
foreach(glob('*.*') as $file){
echo '<option value="'.$file.'">'.$file.'</option>'."\n";
}
echo '</select>';
?>
<input type="submit" name="submit" value="Delete!"
</form>
[/code]

You might want to secure that a bit though.
Link to comment
Share on other sites

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.