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
https://forums.phpfreaks.com/topic/28122-simple-delete-file-form/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.