MCPcopy Create free account
hub / github.com/error311/FileRise / handleUpload

Method handleUpload

src/FileRise/Domain/UploadModel.php:874–1361  ·  view source on GitHub ↗
(array $post, array $files)

Source from the content-addressed store, hash-verified

872 }
873
874 public static function handleUpload(array $post, array $files): array
875 {
876 $storage = StorageRegistry::getAdapter();
877 $isLocal = self::isLocalSourceType();
878 if (!$isLocal && $storage->isLocal()) {
879 return ['error' => 'Remote storage adapter unavailable.'];
880 }
881
882 // --- GET resumable test (make folder handling consistent) ---
883 if (
884 (($_SERVER['REQUEST_METHOD'] ?? 'GET') === 'GET')
885 && isset($post['resumableChunkNumber'], $post['resumableIdentifier'])
886 ) {
887 $chunkNumber = (int)($post['resumableChunkNumber'] ?? 0);
888 $resumableIdentifier = self::normalizeResumableIdentifier($post['resumableIdentifier'] ?? '');
889 $folderSan = self::sanitizeFolder((string)($post['folder'] ?? 'root'));
890
891 if ($chunkNumber < 1 || $resumableIdentifier === null) {
892 return ['error' => 'Invalid resumable upload request'];
893 }
894
895 $baseUploadDir = self::stagingRoot($isLocal);
896 if ($folderSan !== '') {
897 $baseUploadDir = rtrim($baseUploadDir, '/\\') . DIRECTORY_SEPARATOR
898 . str_replace('/', DIRECTORY_SEPARATOR, $folderSan) . DIRECTORY_SEPARATOR;
899 }
900
901 $tempDir = self::resumableTempDir($baseUploadDir, $resumableIdentifier);
902 if ($tempDir === null) {
903 return ['error' => 'Invalid resumable upload request'];
904 }
905 $chunkFile = $tempDir . $chunkNumber;
906
907 return ['status' => file_exists($chunkFile) ? 'found' : 'not found'];
908 }
909
910 // --- CHUNKED (Resumable.js POST uploads) ---
911 if (isset($post['resumableChunkNumber'])) {
912 $chunkNumber = (int)$post['resumableChunkNumber'];
913 $totalChunks = (int)$post['resumableTotalChunks'];
914 $resumableIdentifier = self::normalizeResumableIdentifier($post['resumableIdentifier'] ?? '');
915 $resumableFilename = self::normalizeUploadFileName($post['resumableFilename'] ?? '');
916 $relativeSubDir = '';
917
918 if ($chunkNumber < 1 || $totalChunks < 1 || $chunkNumber > $totalChunks || $resumableIdentifier === null || $resumableFilename === null) {
919 return ['error' => 'Invalid resumable upload request'];
920 }
921
922 if (!empty($post['resumableRelativePath'])) {
923 [$subDir, $relFile] = self::parseRelativePath((string)$post['resumableRelativePath']);
924 if ($subDir === null) {
925 return ['error' => 'Invalid relative path'];
926 }
927 if ($relFile !== '') {
928 $resumableFilename = $relFile;
929 }
930 $relativeSubDir = $subDir;
931 }

Calls 15

isLocalSourceTypeMethod · 0.95
sanitizeFolderMethod · 0.95
stagingRootMethod · 0.95
resumableTempDirMethod · 0.95
parseRelativePathMethod · 0.95
markResumablePendingMethod · 0.95
ensureDirMethod · 0.95
isPathWithinRootMethod · 0.95
rrmdirMethod · 0.95

Tested by

no test coverage detected