Check file size

filesize() function

<?php
$filename = 'example.txt';

$filesize = filesize($filename);

if ($filesize !== false) {
    echo "The size of the file is: $filesize bytes";
} else {
    echo "Failed to get the file size.";
}
?>

Check file type

finfo_file() function

<?php
$filename = 'example.jpg';

$file_info = finfo_open(FILEINFO_MIME_TYPE);
$mime_type = finfo_file($file_info, $filename);
finfo_close($file_info);

echo "The file type is: $mime_type";
?>

Check file extension

<?php
$filename = 'example.txt';

$extension = pathinfo($filename, PATHINFO_EXTENSION);

if (!empty($extension)) {
    echo "The file extension is: $extension";
} else {
    echo "The file has no extension.";
}
?>

Check if date is last day of month

<?php
function isLastDayOfMonth($dateToCheck) {
    $dateObj = new DateTime($dateToCheck);
    $currentMonth = $dateObj->format('m');
    $nextDay = clone $dateObj;
    $nextDay->modify('+1 day');
    $nextMonth = $nextDay->format('m');
    return $currentMonth !== $nextMonth;
}

$dateToCheck = '2024-04-30';

if (isLastDayOfMonth($dateToCheck)) {
    echo "The date $dateToCheck is the last day of the month.";
} else {
    echo "The date $dateToCheck is not the last day of the month.";
}
?>

Check if date is within 30 days

<?php
function isDateWithin30Days($dateToCheck) {
    $dateToCheckObj = new DateTime($dateToCheck);
    $thirtyDaysFromNow = new DateTime('+30 days');
    return $dateToCheckObj <= $thirtyDaysFromNow;
}

$dateToCheck = '2024-04-18';

if (isDateWithin30Days($dateToCheck)) {
    echo "The date $dateToCheck is within the next 30 days.";
} else {
    echo "The date $dateToCheck is not within the next 30 days.";
}
?>

Check if date is greater than today

<?php
function isDateGreaterThanToday($dateToCheck) {
    $dateToCheckObj = new DateTime($dateToCheck);
    $currentDateObj = new DateTime();
    return $dateToCheckObj > $currentDateObj->setTime(0, 0, 0);
}

$dateToCheck = '2024-04-18';

if (isDateGreaterThanToday($dateToCheck)) {
    echo "The date $dateToCheck is greater than today.";
} else {
    echo "The date $dateToCheck is not greater than today.";
}
?>

Check if date is before today

<?php
function isDateBeforeToday($dateToCheck) {
    $dateToCheckObj = new DateTime($dateToCheck);
    $currentDateObj = new DateTime();
    return $dateToCheckObj < $currentDateObj->setTime(0, 0, 0);
}

$dateToCheck = '2024-04-18';

if (isDateBeforeToday($dateToCheck)) {
    echo "The date $dateToCheck is before today.";
} else {
    echo "The date $dateToCheck is not before today.";
}
?>