Download delete.php from Urban-Guy/Drive: direct link, hf CLI and curl.
- Browser
- Download file 2.73 kB
-
https://huggingface.co/spaces/Urban-Guy/Drive/resolve/main/delete.php
- Command line
-
hf download hf://spaces/Urban-Guy/Drive/delete.php
-
curl -L -o delete.php https://huggingface.co/spaces/Urban-Guy/Drive/resolve/main/delete.php
2.73 kB
| session_start(); | |
| $metadataFile = 'data/files.json'; | |
| function loadMetadata() { | |
| global $metadataFile; | |
| if (!file_exists($metadataFile)) return ['files' => []]; | |
| return json_decode(file_get_contents($metadataFile), true); | |
| } | |
| function saveMetadata($metadata) { | |
| global $metadataFile; | |
| file_put_contents($metadataFile, json_encode($metadata, JSON_PRETTY_PRINT)); | |
| } | |
| function deleteDirectory($dir) { | |
| if (!is_dir($dir)) return; | |
| $files = array_diff(scandir($dir), ['.', '..']); | |
| foreach ($files as $file) { | |
| $path = $dir . '/' . $file; | |
| is_dir($path) ? deleteDirectory($path) : unlink($path); | |
| } | |
| rmdir($dir); | |
| } | |
| if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['fileIds'])) { | |
| $fileIds = json_decode($_POST['fileIds'], true); | |
| if (!is_array($fileIds)) { | |
| $fileIds = [$_POST['fileId']]; | |
| } | |
| $metadata = loadMetadata(); | |
| $deletedCount = 0; | |
| foreach ($fileIds as $fileId) { | |
| foreach ($metadata['files'] as $key => $file) { | |
| if ($file['id'] === $fileId) { | |
| // Delete actual file or folder | |
| if ($file['type'] === 'folder') { | |
| if (is_dir($file['path'])) { | |
| deleteDirectory($file['path']); | |
| } | |
| } else { | |
| if (file_exists($file['path'])) { | |
| unlink($file['path']); | |
| } | |
| } | |
| // Remove from metadata | |
| unset($metadata['files'][$key]); | |
| $deletedCount++; | |
| break; | |
| } | |
| } | |
| } | |
| $metadata['files'] = array_values($metadata['files']); | |
| saveMetadata($metadata); | |
| echo json_encode(['success' => true, 'deletedCount' => $deletedCount]); | |
| exit; | |
| } | |
| // Single file delete (backward compatibility) | |
| if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['fileId'])) { | |
| $fileId = $_POST['fileId']; | |
| $metadata = loadMetadata(); | |
| foreach ($metadata['files'] as $key => $file) { | |
| if ($file['id'] === $fileId) { | |
| if ($file['type'] === 'folder') { | |
| if (is_dir($file['path'])) { | |
| deleteDirectory($file['path']); | |
| } | |
| } else { | |
| if (file_exists($file['path'])) { | |
| unlink($file['path']); | |
| } | |
| } | |
| unset($metadata['files'][$key]); | |
| $metadata['files'] = array_values($metadata['files']); | |
| saveMetadata($metadata); | |
| echo json_encode(['success' => true]); | |
| exit; | |
| } | |
| } | |
| echo json_encode(['success' => false]); | |
| } | |