If you have put such a script on your website in which many files are saved on your website daily and you have to delete those files manually, you want to delete all those files in one click from PHP script automatically. you can do it.

If you can delete any type of file from any folder of File Manager, then whether it is pdf, jpg, png, mp4, vidoe, mp3, html, css, js, php, py you can delete all these files. , see below for how to delete.

Image / PDF / Video / Other File Delete Automatically in File Manager Folder

To delete any type of file from any folder, follow the steps given below.

Step 1: – First of all, open the file manager of the kernel, in it in any folder or anywhere in public_html, create a new file by the name of autodelete.php

Step 2: – Then edit the autodelete.php file and paste a code in it which is named

Step 3: – If you want to delete all the files related to that type at once, then you can use this code.

<?php
// Delete the given file
$files = glob('foldername/*.jpg'); // enter your file type .jpg to .pdf or .png etc.
foreach($files as $file) {
    unlink($file);
}
?>

If you run the above mentioned code, then the folder whose name will be given in your code and the type of file you have entered, all the files will be deleted.

Step 4:- If you want to delete only one file at a time, then how can you do it, for this use the code given below, in which you will get the name of the folder and the name of the file.

<?php
// Delete the given folder file
    unlink('folder/photo.jpg');
?>

Or

<?php
// Delete the given file
    unlink('photo.jpg');
?>

By using the above mentioned code, you can download jpg file, pdf file, png file,doc file,php file,html file,css file from any folder.

Leave a Reply

Your email address will not be published. Required fields are marked *