} $pl[$relfile] = array(); } return $pl; } require PLAYLIST_DIR . '/' . $playlist . '.php'; if (!file_exists('cache/')) { mkdir('cache/'); } $json = array(); foreach ($playlist as $file => $data) { list(, $ext) = explode('.', $file); if (!in_array($ext, $validExtensions)) { continue; } $json[] = analyzeFile($file, $data); } function analyzeFile($file, $playlist_data) { global $validExtensions, $getID3; $fileURL = BASE_URL . '/files/' . $file; $file = FILE_DIR . '/' . $file; // use cache, if available $cachefile = 'cache/' . md5($file) . '.cache.php'; if (file_exists($cachefile)) { require $cachefile; $row = array_merge($row, $playlist_data); return $row; } // Get ID3 tags and whatnot $data = $getID3->analyze($file);
list($name, $type) = explode(".", basename($mrFiles)); $views[$name][$type] = file_get_contents($mrFiles); } $view = array("_id" => "_design/files", "type" => "view", "language" => "javascript", "views" => $views); // Add the view $s->post($view); // Delete all cache entries as to not accumulate too many foreach (glob($cachePath . "/*") as $cacheEntry) { unlink($cacheEntry); } // Import all new entries foreach (glob($fileStorageDir . "/*") as $userDir) { $userName = trim(base64_decode(basename($userDir))); foreach (glob($userDir . "/*") as $userFile) { if (!is_file($userFile)) { continue; } echo "[{$userName}] Analyzing: " . basename($userFile) . "\n"; $metaData = new stdClass(); $metaData->fileName = basename($userFile); analyzeFile($metaData, dirname($userFile), $cachePath); $metaData->fileOwner = $userName; $metaData->fileTags = array('Demo Tag', "Length" . strlen(basename($userFile))); $metaData->fileDescription = 'Imported on ' . strftime("%c", time()); $metaData->fileGroups = array(); $metaData->fileTokens = array(); $metaData->fileLicense = 'none'; $metaData->fileTags = array(); $s->post($metaData); } }
<?php include "../utils.php"; if (empty($argv[1]) || !is_file($argv[1])) { die("specify full file path for file to analyze\n"); } $metaData = array(); $metaData['fileName'] = basename($argv[1]); analyzeFile($metaData, dirname($argv[1]), '/tmp'); var_dump($metaData);
function handleUpload() { $ownerDir = base64_encode($this->auth->getUserId()); $targetDir = getConfig($this->config, 'file_storage_dir', TRUE) . "/{$ownerDir}"; $cachePath = getConfig($this->config, 'cache_dir', TRUE); if (!file_exists($targetDir)) { @mkdir($targetDir); } $httpHeaders = getallheaders(); if (array_key_exists('X-Requested-With', $httpHeaders) && $httpHeaders['X-Requested-With'] === "XMLHttpRequest" && array_key_exists('X-File-Name', $httpHeaders) && array_key_exists('X-File-Size', $httpHeaders)) { $fileName = basename($httpHeaders['X-File-Name']); $fileSize = $httpHeaders['X-File-Size']; $fileChunk = 0; if (array_key_exists('X-File-Chunk', $httpHeaders)) { $fileChunk = $httpHeaders['X-File-Chunk']; } $fileName = filter_var($fileName, FILTER_SANITIZE_SPECIAL_CHARS); if ($fileName === FALSE) { logHandler("Invalid X-File-Name '" . $fN . "' by user '" . $this->auth->getUserId() . "'"); die; } if (!is_numeric($fileSize) || $fileSize < 0) { logHandler("Invalid X-File-Size '" . $fileSize . "' by user '" . $this->auth->getUserId() . "'"); die; } $fileSize = (int) $fileSize; if (!is_numeric($fileChunk) || $fileChunk < 0) { logHandler("Invalid X-File-Chunk '" . $fileChunk . "' by user '" . $this->auth->getUserId() . "'"); die; } $fileChunk = (int) $fileChunk; $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $fileChunk == 0 ? "wb" : "ab"); if ($out) { $in = fopen("php://input", "rb"); if ($in) { while ($buffer = fread($in, 4096)) { fwrite($out, $buffer); } } else { // FIXME: failed to open input stream } fclose($in); fclose($out); flush(); /* only check file when upload is complete */ if ($fileSize == filesize($targetDir . DIRECTORY_SEPARATOR . $fileName)) { $metaData = new stdClass(); $metaData->fileName = $fileName; analyzeFile($metaData, $targetDir, $cachePath); $metaData->fileOwner = $this->auth->getUserId(); $metaData->fileDescription = 'Uploaded on ' . strftime("%c", time()); $metaData->fileGroups = array(); $metaData->fileTokens = array(); $metaData->fileLicense = 'none'; $metaData->fileTags = array(); $this->storage->post($metaData); logHandler("User '" . $this->auth->getUserID() . "' uploaded file '" . $metaData->fileName . "'"); } } else { // FIXME: failed to open output stream } } exit(0); }