Your IP : 216.73.216.1
<?php
function displayFileSize() {
$file_pointer = "count.txt";
if (file_exists($file_pointer)) {
$file_size = filesize($file_pointer);
echo "Size of $file_pointer: " . formatSize($file_size) . "<br>";
} else {
echo "File does not exist.<br>";
}
}
function formatSize($bytes) {
$units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
$factor = (int)floor(log($bytes, 1024));
return sprintf("%.2f", $bytes / pow(1024, $factor)) . ' ' . $units[$factor];
}
function countRecords($file_pointer) {
if (file_exists($file_pointer)) {
$lines = file($file_pointer);
return count($lines);
}
return 0;
}
if (isset($_POST['delete'])) {
$file_pointer = "count.txt";
if (file_exists($file_pointer) && !unlink($file_pointer)) {
echo ("$file_pointer cannot be deleted due to an error<br>");
} else {
echo ("$file_pointer has been deleted<br>");
}
}
if (isset($_POST['add'])) {
$file_pointer = "count.txt";
$current = "New record\n"; // Example content to add
if (file_put_contents($file_pointer, $current, FILE_APPEND) === false) {
echo ("$file_pointer cannot be added due to an error<br>");
} else {
echo ("$file_pointer has been added<br>");
chmod($file_pointer, 0777); // More secure permission setting.
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>File Management</title>
</head>
<body>
<form method="post">
<br>
<button type="submit" name="delete">Delete File</button>
<button type="submit" name="add">Add File</button>
</form>
<br>
<?php
$file_pointer = 'count.txt';
if (file_exists($file_pointer)) {
$file = file_get_contents($file_pointer, true);
$recordCount = countRecords($file_pointer);
echo "<br>LOADS: $recordCount<br><br>";
echo nl2br(htmlspecialchars($file));
} else {
echo "File does not exist.";
}
?>
</body>
</html>