PHP is_file
Check whether a regular receipt file is available for a preview in the cashier's folder.
A simple example
is_file
- Start with No file named a.txt
- Do this Open a.txt for reading
- Result File missing
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.phpOpen 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.
<?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);
}
No receipt yet
The program owns a fresh, empty directory, so in this run the named receipt is known to be absent.
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.
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.
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.