Hello, this is kind of a weird question. I was wondering if there was any way for me to add something to my website, so when the user presses a key combination(alt+h), my website deletes all files in a folder. I have no idea where to start, or whether this could work at all. I don’t need to worry about security, just as long as the user doesn’t have access to deleting any files outside of the folder Thanks for your guidance!
Let’s start with “Why do you want to do this?”.
I have a chat script on my website, and I want a convenient way to clear it. I suppose the key combo idea isn’t necessary, but I need some way to do it without opening up my FTP software, and deleting them manually.
Just a note, that would have been a much better post along with code that writes the files you want to delete. See XY Problem
Anyways, to help you solve the real problem as you have now clarified it would be helpful to see the code that writes the files you want to delete. A link to the chat script you are using would also be helpful if there is one.
Sure. The script I am using is unmodified. Here’s the GitHub. https://github.com/C3La-NS/ChatX
A quick read of the code looks like they have made it easy.
load.php line 5
// If you want to delete old comments, make this true. We use it to clean up the demo.
$deleteOldComments = false;
I completely forgot about that. It deletes comments after two days. How could I incorporate this? I have no experience with php. How could I adapt it to delete all files, instead of checking for the timestamp inside? Then, trigger the deletion with javascript or something?
if($deleteOldComments) {
$oldShouts = $repo->query()
->where('createdAt', '<', strtotime('-3 days'))
->execute();
foreach($oldShouts as $old) {
$repo->delete($old->id);
}
}
How could this be done?
Make these two changes to delete all chat data
$deleteOldComments = true;
Comment out this line with //
//->where(‘createdAt’, ‘<’, strtotime(‘-3 days’))
Yeah, but I only want to clear it when I press a button
Then just throw in a button where you want it and add an if statement to the code that deletes the files.
How would you do that? I’ve never touched PHP before.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.