Library contents

PHP is_file

Check whether a regular receipt file is available for a preview in the cashier's folder.

A simple example

is_file

  1. Start with No file named a.txt
  2. Do this Open a.txt for reading
  3. Result File missing
The missing-path outcome lets the caller offer an empty starting state or ask for another name.

Syntax

PHP syntax
is_file($receipt)
Run these examples in PHP

Save one example at a time as lesson.php. Use PHP 8.2 or later.

php lesson.php

Open the first receipt of the day

A new checkout starts with an empty receipt folder. When the cashier asks to reprint today's first receipt, the app should explain that a receipt has yet to be saved.

ResultNo receipt yet
lesson.php
<?php
$desk = sys_get_temp_dir() . '/checkout-' . bin2hex(random_bytes(12));
if (!mkdir($desk, 0700)) {
    throw new RuntimeException('Could not open a receipt workspace');
}
try {
    if (!is_file($desk . '/today.txt')) {
        echo 'No receipt yet';
    }
} finally {
    rmdir($desk);
}
Output
No receipt yet

The program owns a fresh, empty directory, so in this run the named receipt is known to be absent.

Advertisements

Read a saved shift record

The closing clerk saved the file before leaving. Open the expected file and show the desk whether it is available.

Givenrecord.txt exists
Worked resultFile available

Handle an unsubmitted handover

The next shift opens an empty inbox before the first clerk submits a file. Open the expected file and show the desk whether it is available.

Givenrecord.txt missing
Worked resultAsk for the file

What to watch for

A false result can have other causes outside this fresh folder. Check the read operation too when printing a real receipt.

Documentation for is_file