Download copy.php from Urban-Guy/Drive: direct link, hf CLI and curl.
- Browser
- Download file 1.86 kB
-
https://huggingface.co/spaces/Urban-Guy/Drive/resolve/main/copy.php
- Command line
-
hf download hf://spaces/Urban-Guy/Drive/copy.php
-
curl -L -o copy.php https://huggingface.co/spaces/Urban-Guy/Drive/resolve/main/copy.php
1.86 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)); | |
| } | |
| if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['fileId'])) { | |
| $fileId = $_POST['fileId']; | |
| $metadata = loadMetadata(); | |
| foreach ($metadata['files'] as $file) { | |
| if ($file['id'] === $fileId) { | |
| $pathInfo = pathinfo($file['name']); | |
| $copyName = $pathInfo['filename'] . ' (copy)'; | |
| if (isset($pathInfo['extension'])) $copyName .= '.' . $pathInfo['extension']; | |
| $copyPath = dirname($file['path']) . '/' . $copyName; | |
| $counter = 1; | |
| while (file_exists($copyPath)) { | |
| $copyName = $pathInfo['filename'] . ' (copy ' . $counter . ')'; | |
| if (isset($pathInfo['extension'])) $copyName .= '.' . $pathInfo['extension']; | |
| $copyPath = dirname($file['path']) . '/' . $copyName; | |
| $counter++; | |
| } | |
| if (file_exists($file['path']) && copy($file['path'], $copyPath)) { | |
| $newFile = $file; | |
| $newFile['id'] = uniqid(); | |
| $newFile['name'] = $copyName; | |
| $newFile['path'] = $copyPath; | |
| $newFile['created'] = time(); | |
| $newFile['modified'] = time(); | |
| $newFile['starred'] = false; | |
| $metadata['files'][] = $newFile; | |
| saveMetadata($metadata); | |
| echo json_encode(['success' => true]); | |
| exit; | |
| } | |
| } | |
| } | |
| echo json_encode(['success' => false]); | |
| } | |