+3 votes
in Programming Languages by (60.0k points)
I want to delete all image files from a folder if the file size is less than 100KB. How can I check the file size in PHP?

1 Answer

+1 vote
by (353k points)
selected by
Best answer

You can use PHP function filesize() to get the size of the file in bytes. This function requires a filename as an argument and returns file size in bytes on success, FALSE on failure.

Here is an example to check the size and delete a file using PHP.


$filename = "phpinfo.php";
if (filesize($filename) < 100000){
    if (unlink($filename)){
        print("File was deleted successfully\n");
        print("Something went wrong\n");
    print("File is bigger than 100k\n");