Bunghole
Bunghole

Reputation: 55

Check if file exists AND is greater than

I need to check if a file in the same folder as the script exists and is greater than 100 Bytes, if so echo "is there".

Upvotes: 2

Views: 7962

Answers (2)

Winter
Winter

Reputation: 1741

I believe you're trying to do something like this:

$filename = 'test.txt';

if (file_exists($filename) && filesize($filename) > 100) {
    echo "is there";
} else {
    echo "not there";
}

Read the PHP documentation of filesize and file_exists for a more in-depth explanation.

Upvotes: 9

Lajos Veres
Lajos Veres

Reputation: 13725

Maybe something like this?

if(file_exists($filename) && filesize($filename) >100){
  echo "is there";
}

Upvotes: 2

Related Questions